SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select AS with CAST
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

djs42
Starting Member

Canada
4 Posts

Posted - 06/13/2013 :  11:27:07  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 06/13/2013 :  11:42:25  Show Profile  Reply with Quote
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

Edited by - MIK_2008 on 06/13/2013 11:44:08
Go to Top of Page

djs42
Starting Member

Canada
4 Posts

Posted - 06/13/2013 :  12:23:18  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 06/13/2013 :  12:35:51  Show Profile  Reply with Quote
you're welcome~!

Cheers
MIK
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000