bbenedict Posted December 10, 2012 Share Posted December 10, 2012 Need to convert some columns to different data type, but this statement will not work. Any idea what I am missing? (mgmt Studio has the first 'CAST' and 'AS' underlined. SELECT CAST [ETL_ID as int] as ETL_ID, NAMEX, DU_DEGREE_STATUS, DU_ESTS_DESC, Cast [bANNER_ID as (varchar(36),Null)]as BANNER_ID, DU_COLLEGE_DESC, cAST [DU_DEL_TERM_CODE_ADMIT as (VARCHAR(255),NULL)] AS DU_DEL_TERM_CODE_ADMIT, AGE, ETHNICITY_DESCRIPTION, GENDER, cAST [T1 as (VARCHAR(255),NULL)] AS T1, T1Status, cAST [T2 as (VARCHAR(255),NULL)] as T2, T2Status, cAST [T3 as (VARCHAR(255),NULL)] as T3, T3Status, cAST [T4 as (VARCHAR(255),NULL)] as T4, T4StatusFROM dbo.['Tracking 3$'] Link to comment Share on other sites More sharing options...
justsomeguy Posted December 10, 2012 Share Posted December 10, 2012 What database are you using? Does it support that syntax? Link to comment Share on other sites More sharing options...
bbenedict Posted December 10, 2012 Author Share Posted December 10, 2012 Mgmt studio Link to comment Share on other sites More sharing options...
justsomeguy Posted December 10, 2012 Share Posted December 10, 2012 If "mgmt studio" refers to Microsoft SQL Server, then there is a reference for using cast here that includes examples: http://msdn.microsoft.com/en-us/library/ms187928.aspx Importantly, it does not use square brackets, only parentheses. Link to comment Share on other sites More sharing options...
bbenedict Posted December 27, 2012 Author Share Posted December 27, 2012 Thanks! So i got this to work but there is still one wierd problem, when the cast statement is executed the values in one of the colums goes through this transformation: original (float, null) - 12594570New (after: CAST(thing_ID AS VARCHAR(36)) AS Thing_ID) 1.25946e+007 In the warehouse I cannot link these notations with the fact table. Link to comment Share on other sites More sharing options...
bbenedict Posted December 27, 2012 Author Share Posted December 27, 2012 Update: I inserted ,Cast(CAST(BANNER_ID AS VARCHAR(50))as decimal) as BANNER_ID to try and fix the notication and return it back to a simple number and now I get this 'Error converting data type varchar to numeric." so i think i am getting closer. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 7, 2013 Share Posted January 7, 2013 Why do you need to cast at all? Why not just return the original number? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now