Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select AS with CAST

Author  Topic 

djs42
Starting Member

4 Posts

Posted - 2013-06-13 : 11:27:07
I have several views in which I rename the data fields:

SELECT
Name,
Item10 AS Value,
Item11 AS Type,
Item29 AS LastField
FROM dbo.database
WHERE (LEFT(Name,3)='11-')
ORDER BY Name

I want to use CAST to define the data type returned by the views:

CAST (Value as VARCHAR)

What is the correct syntax for both renaming and CASTing the data type?

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-06-13 : 11:42:25
is this something you're looking for?

SELECT
Name,
CAST(Item10 as Varchar(specify the length in which item10 value can get fit in)) AS Value,
....
...
..
Order By Name


Cheers
MIK
Go to Top of Page

djs42
Starting Member

4 Posts

Posted - 2013-06-13 : 12:23:18
MIK,

Thanks - works exactly as I want!

Stringing together SQL in the correct syntax always seems to be my biggest hurdle.
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-06-13 : 12:35:51
you're welcome~!

Cheers
MIK
Go to Top of Page
   

- Advertisement -