Showing posts with label functions. Show all posts
Showing posts with label functions. Show all posts

Tuesday, March 27, 2012

Converting Data Types

I need to be able to convert a numeric data type to a text data type.

I've tried the TO_CHAR and the DBCONVERT functions but I am returned an error stating that they are not recognized functions.

I'm using the Query Analyzer on a Windows 2000 SQL Server.

Any help would be appreciated.

TechRickYou can use the cast or convert functions.|||Thanks,

I was just reading up on the CAST function. However, I've not been able to make it work yet.

In correction to my original post, I need to take a MONEY data type and convert it to a TEXT data type. I hope this possible.

Thanks again,

TechRick|||Try the following from the pubs database and titles table:

SELECT price, cast(price AS varchar(30)) FROM titles|||You can also do it this way:

select cast(cast(price as varchar(30)) as text) from titles

But since the conversion is implicit between varchar and text you don't need to do this.|||Thanks again for the help. Your suggestion works great but when I try to update the data I get this:

Server: Msg 260, Level 16, State 1, Line 31
Disallowed implicit conversion from data type varchar to data type money, table..., column 'PRICE'. Use the CONVERT function to run this query.
Server: Msg 257, Level 16, State 1, Line 31
Implicit conversion from data type money to varchar is not allowed. Use the CONVERT function to run this query.

I'll let you know once I get it worked out.

Best Regards,
TechRick|||The way the error is reading is that you are trying to put a varchar into a money column - is that correct ?|||Yes, I have a large list of items collected from various tables and there are prices associated with these items. A good majority of these items have no price (.0000) and I would like to exchange the .0000 price for a 'CALL' or something similar.

I could not update the records with a "text" substitute so I thought I would convert the data type to TEXT so I can plug in whatever I want.

Thanks again,
TechRick|||Why did you choose text over varchar ? Could you post your update statement as well as the definition of the table you are updating ? You have to explicitly convert varchar to money and vice-versa using either cast or convert. But I am a little confused about the first error you received - why are you trying to put a varchar into a money column ?|||You'll have to excuse me, I've only been working with SQL for less than 3 weeks. I've been learning as I go (with my Dummies and Sam's books and this forum). I've already written a few complex queries and as for this particular situation, this is the last obsticle I need to overcome to put this query to rest.

Based on the error I was getting I assumed that I was doing something wrong but I didn't have the time to completely research it. I'll pick it back up on Monday. I think I need to understand the convert and cast functions better before I can make use of them. I'll be working towards that end.

As for now, I'm away from work and don't have easy access to the code. I'll post it Monday after I tinker a little more.

Thanks for the help.

TechRick|||Ah, by "convert" you mean that you would like to change the data type of a column from money to varchar so that you can store a mix of data in a single column. The easy answer is to just change the data type of the column in Enterprise Manager. If SQL Server can find a reasonable way to preserve the data, it will. Thereafter you can store any character data in the column, e.g. "Call" or "Operators are standing by!".

The "correct" answer is rather different, and a valid subject for debate. If you do not have a price for an item, the correct representation in the database should be different from a free item. For example, you might use the value NULL to indicate "call for price" and $0.00 for a free item. Alternatively, it may make more sense in your application to have a separate means of flagging items for which you don't want to publish a price, qualify for free shipping, have quantity discounts, ... . More columns or tables may be needed.|||Agreed about the 'correct' answer. Fortunately and unfortunately, I didn't write the application so I'm working with what's there.

I managed to get it taken care of by adding the convert on my select statment.

SELECT UPPER(ITEM), DESCRIPT, Q_STK, QTY_RESERVE, CAST (SELLPRICE AS VARCHAR(15)),...

By doing it this way I am able to manipulate the data any way I want.
Add 'CALL', 'FREE', etc.

Thanks all for the help. One last item and this query is behind me.

Best Regards,
TechRick|||Originally posted by rnealejr
Try the following from the pubs database and titles table:

SELECT price, cast(price AS varchar(30)) FROM titles

rnealejr, I noticed as I was going back through all these posts that you were right on the money a long time ago! Thanks for the help. I think I was trying to perform an update on the column using the cast rather than taking the data in converted from the start. Anyhow, just wanted to thank you for your help. Too bad I had to learn the hard way.

Best Regards,
TechRick|||Thanks for the email and compliment as well as a good pun (right on the money) - I enjoyed that.

Good luck.|||Another handy tool for fudging return values within a query is throwing in a CASE, e.g.:

select Description, ServingSize, case when Price<>0.0 then Convert(VarChar,Price) else 'Call' end as 'AdvertisedPrice'
from PiecesParts where Fused=1

Note that there are two slightly different versions of CASE. One lets you test a single expression against multiple values, while the other lets you test multiple expressions.

You can swindle a lot of logic into a CASE or nested CASEs. For example, it could check for quantity price breaks or apply discounts based on data from other tables or variables. The result is just another (computed) column in the recordset returned from the query. (As such, it isn't writable.)

converting Crystal Reports to SSRS

I came across a website that claimed "There are approximately 116 functions in Crystal Reports that do not have a direct equivalent in VB.NET or Reporting Services (SSRS)." Does anyone know what these functions are?I know this is not a direct answer to your question, but we looked into a way to convert Crystal Reports to SQL Reports, but were unable to find a viable solution. There is an application called RPT2RDL that claims to convert some files, but it does not handle a good many functions even though some are supported by SQL Reporting Services. This has left us manually recreating the reports which takes a great deal of time.

Thursday, March 8, 2012

CONVERT statement - Invalid Column Name

Hi All,
After digging out some information on using the CONVERT and CAST
functions to convert a string to a date, I am still having a problem
that I do not understand?
In an attempt to convert a Legacy format for a date e.g. '19960905'
imported into MS SQL Server into a correctly sequenced and delimetered
data '05/09/1996' I am using the following statement for two columns in
my table. Both receive the following exception messages
Column Name = 'DATE_ORIGINAL'
SELECT CONVERT(char(10), CAST(CAST(DATE_ORIGINAL AS char(8)) AS
datetime), 103)
MS SQL Server throws the following exception:
'Invalid column name 'DATE_ORIGINAL'
Column Name = 'DATE_RESCHEDULED'
SELECT CONVERT(char(10), CAST(CAST(DATE_RESCHEDULED AS char(8)) AS
datetime), 103)
MS SQL Server throws the following exception:
'Invalid column name 'DATE_RESCHEDULED'
I have triple checked both column names and they are both correct. Does
anyone know why these errors occur when I try to run this statement?
Does the use of the word DATE have something to do with it perhaps?
Many Thanks
rohanIf these are the entire select statements, you are
forgetting to include the FROM table name - such as
SELECT CONVERT(char(10), CAST(CAST(DATE_ORIGINAL AS char(8))
AS datetime), 103)
FROM YourTable
-Sue
On 25 Sep 2006 02:18:14 -0700, "red vertigo"
<rohankinsella@.hotmail.com> wrote:
>Hi All,
>After digging out some information on using the CONVERT and CAST
>functions to convert a string to a date, I am still having a problem
>that I do not understand?
>In an attempt to convert a Legacy format for a date e.g. '19960905'
>imported into MS SQL Server into a correctly sequenced and delimetered
>data '05/09/1996' I am using the following statement for two columns in
>my table. Both receive the following exception messages
>Column Name = 'DATE_ORIGINAL'
>SELECT CONVERT(char(10), CAST(CAST(DATE_ORIGINAL AS char(8)) AS
>datetime), 103)
>MS SQL Server throws the following exception:
>'Invalid column name 'DATE_ORIGINAL'
>Column Name = 'DATE_RESCHEDULED'
>SELECT CONVERT(char(10), CAST(CAST(DATE_RESCHEDULED AS char(8)) AS
>datetime), 103)
>MS SQL Server throws the following exception:
>'Invalid column name 'DATE_RESCHEDULED'
>I have triple checked both column names and they are both correct. Does
>anyone know why these errors occur when I try to run this statement?
>Does the use of the word DATE have something to do with it perhaps?
>Many Thanks
>rohan|||Hi Sue,
Thankyou very much indeed for replying to my post.
Can't believe I left that part off my statement (lol).
This statement works correctly now.
Your help is greatly appreciated.
rohan
Sue Hoegemeier wrote:
> If these are the entire select statements, you are
> forgetting to include the FROM table name - such as
> SELECT CONVERT(char(10), CAST(CAST(DATE_ORIGINAL AS char(8))
> AS datetime), 103)
> FROM YourTable
> -Sue
> On 25 Sep 2006 02:18:14 -0700, "red vertigo"
> <rohankinsella@.hotmail.com> wrote:
> >Hi All,
> >After digging out some information on using the CONVERT and CAST
> >functions to convert a string to a date, I am still having a problem
> >that I do not understand?
> >
> >In an attempt to convert a Legacy format for a date e.g. '19960905'
> >imported into MS SQL Server into a correctly sequenced and delimetered
> >data '05/09/1996' I am using the following statement for two columns in
> >my table. Both receive the following exception messages
> >
> >Column Name = 'DATE_ORIGINAL'
> >SELECT CONVERT(char(10), CAST(CAST(DATE_ORIGINAL AS char(8)) AS
> >datetime), 103)
> >
> >MS SQL Server throws the following exception:
> >
> >'Invalid column name 'DATE_ORIGINAL'
> >
> >Column Name = 'DATE_RESCHEDULED'
> >SELECT CONVERT(char(10), CAST(CAST(DATE_RESCHEDULED AS char(8)) AS
> >datetime), 103)
> >
> >MS SQL Server throws the following exception:
> >
> >'Invalid column name 'DATE_RESCHEDULED'
> >
> >I have triple checked both column names and they are both correct. Does
> >anyone know why these errors occur when I try to run this statement?
> >
> >Does the use of the word DATE have something to do with it perhaps?
> >
> >Many Thanks
> >
> >rohan|||Hi Rohan
Please note that '19960905' is not in a legacy format. It is actually a
recommended format when working with date data in SQL Server because it is
completely unambiguous. Your desired format of '05/09/1996' could hardly be
called 'correctly sequenced and delimetered (')' for everyone, since
different people use different delimiters, like dashes or dots, and it is
ambiguous depending on the local. In the US, '05/09/1996' is interpreted as
May 9th. So if '05/09/1996' is what your users are hoping for, that is
fine and at some point in the client app you'll probably want to give it to
them. But just be careful.
--
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"red vertigo" <rohankinsella@.hotmail.com> wrote in message
news:1159175894.377984.228190@.h48g2000cwc.googlegroups.com...
> Hi All,
> After digging out some information on using the CONVERT and CAST
> functions to convert a string to a date, I am still having a problem
> that I do not understand?
> In an attempt to convert a Legacy format for a date e.g. '19960905'
> imported into MS SQL Server into a correctly sequenced and delimetered
> data '05/09/1996' I am using the following statement for two columns in
> my table. Both receive the following exception messages
> Column Name = 'DATE_ORIGINAL'
> SELECT CONVERT(char(10), CAST(CAST(DATE_ORIGINAL AS char(8)) AS
> datetime), 103)
> MS SQL Server throws the following exception:
> 'Invalid column name 'DATE_ORIGINAL'
> Column Name = 'DATE_RESCHEDULED'
> SELECT CONVERT(char(10), CAST(CAST(DATE_RESCHEDULED AS char(8)) AS
> datetime), 103)
> MS SQL Server throws the following exception:
> 'Invalid column name 'DATE_RESCHEDULED'
> I have triple checked both column names and they are both correct. Does
> anyone know why these errors occur when I try to run this statement?
> Does the use of the word DATE have something to do with it perhaps?
> Many Thanks
> rohan
>|||Hi Karen,
Interesting. Thanks for the information.
rohan
Kalen Delaney wrote:
> Hi Rohan
> Please note that '19960905' is not in a legacy format. It is actually a
> recommended format when working with date data in SQL Server because it is
> completely unambiguous. Your desired format of '05/09/1996' could hardly be
> called 'correctly sequenced and delimetered (')' for everyone, since
> different people use different delimiters, like dashes or dots, and it is
> ambiguous depending on the local. In the US, '05/09/1996' is interpreted as
> May 9th. So if '05/09/1996' is what your users are hoping for, that is
> fine and at some point in the client app you'll probably want to give it to
> them. But just be careful.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> http://sqlblog.com
>
> "red vertigo" <rohankinsella@.hotmail.com> wrote in message
> news:1159175894.377984.228190@.h48g2000cwc.googlegroups.com...
> > Hi All,
> > After digging out some information on using the CONVERT and CAST
> > functions to convert a string to a date, I am still having a problem
> > that I do not understand?
> >
> > In an attempt to convert a Legacy format for a date e.g. '19960905'
> > imported into MS SQL Server into a correctly sequenced and delimetered
> > data '05/09/1996' I am using the following statement for two columns in
> > my table. Both receive the following exception messages
> >
> > Column Name = 'DATE_ORIGINAL'
> > SELECT CONVERT(char(10), CAST(CAST(DATE_ORIGINAL AS char(8)) AS
> > datetime), 103)
> >
> > MS SQL Server throws the following exception:
> >
> > 'Invalid column name 'DATE_ORIGINAL'
> >
> > Column Name = 'DATE_RESCHEDULED'
> > SELECT CONVERT(char(10), CAST(CAST(DATE_RESCHEDULED AS char(8)) AS
> > datetime), 103)
> >
> > MS SQL Server throws the following exception:
> >
> > 'Invalid column name 'DATE_RESCHEDULED'
> >
> > I have triple checked both column names and they are both correct. Does
> > anyone know why these errors occur when I try to run this statement?
> >
> > Does the use of the word DATE have something to do with it perhaps?
> >
> > Many Thanks
> >
> > rohan
> >

Friday, February 24, 2012

convert Ms SQL to Oracle

What is the fastest and more simple way to convert MS SQL database (tables, procedures, functions, views) in Oracle DB?
Thanks
Franky
Franky@.jepca.comuh you should push it from SQL Server to Oracle using SQL Server DTS-- obvioulsy the best ETL tool in the world.

why would you possibly move from SQL Server to Oracle again?

you know that SQL Server is rated as the faster db at www.tpc.org??|||Originally posted by aaron_kempf
uh you should push it from SQL Server to Oracle using SQL Server DTS-- obvioulsy the best ETL tool in the world.

why would you possibly move from SQL Server to Oracle again?

you know that SQL Server is rated as the faster db at www.tpc.org??

If I'm not wrong, there is a free tool to convert MS SQL to Oracle. Try checking out from Oracle. I personally wouldnt trust a tool from M$ to convert MS SQL to another DB. U think M$ would wanna loose money?? :)

Anyway, I cant seem to find the tool now. If u can wait, I'll post it as soon as I find it.|||uh its free with sql server also

www.sqldts.com

and you can access any DBMS with the tool-- but then again you need to install the Oracle Client software on the server if you want to do anything on a scheduled basis

im just tired of dealing with bloatware like a application servers and all that other garbage.

i dont want to install a webserver when i install oracle!!!
i mean-- why would i EVER install APACHE on windows?|||Originally posted by aaron_kempf
uh you should push it from SQL Server to Oracle using SQL Server DTS-- obvioulsy the best ETL tool in the world.

why would you possibly move from SQL Server to Oracle again?

you know that SQL Server is rated as the faster db at www.tpc.org??

If I'm not wrong, there is a free tool to convert MS SQL to Oracle. Try checking out from Oracle. I personally wouldnt trust a tool from M$ to convert MS SQL to another DB. U think M$ would wanna loose money?? :)

Anyway, I cant seem to find the tool now. If u can wait, I'll post it as soon as I find it.