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.
| Author |
Topic |
|
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2012-09-12 : 06:00:10
|
| Hey guys i am receiving this error msg Msg 156, Level 15, State 1, Line 3Incorrect syntax near the keyword 'case'.and this is my query , any ideas ? SELECT u.DBA_Name,u.parentid, u.Rolling_12,u.post_code,u.NewPostcode,g.[RMSC],dbo.RollingSalesBandRM (u.Rolling_12)as SalesBandinginto #banding FROM [FDMS].[dbo].[Geo_PCA_Sellers] gINNER JOIN #Update uON u.NewPostcode = g.PCA--select * from #banding--drop table #banding ----------------------------------------------------Select * from #bandingcase when Salesbanding in ('50M to 100+')then 'R05'When Salesbanding in ('2M to 5M')then 'R15' else RMSC end as RMSC into #RmUpdate |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-12 : 06:46:13
|
selectcol1,col2,case when ... then ... end as col3into ...from ... Too old to Rock'n'Roll too young to die. |
 |
|
|
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2012-09-12 : 06:50:46
|
| hi webfred Are you stating that it should be select #banding.DBA_Name,#banding.ParentID,#banding.Post_Code,#banding.Rolling_12,#banding.RMSC,#banding.SalesBanding,case when Salesbanding in ('50M to 100+')then 'R05'When Salesbanding in ('2M to 5M')then 'R15'end as RMSC Into #RmUpdateFrom #bandingif thats the case i would get the following error msg Msg 2705, Level 16, State 3, Line 1Column names in each table must be unique. Column name 'RMSC' in table '#RmUpdate' is specified more than once. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-12 : 06:59:11
|
instead of having 2 the same column names, just name your case-column RMSC2 or whatever. Too old to Rock'n'Roll too young to die. |
 |
|
|
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2012-09-12 : 07:09:16
|
| Webfred i am being thick ! its been a long day ! lol Can you answer me this question SELECT u.DBA_Name,u.parentid, u.Rolling_12,u.post_code,u.NewPostcode,g.[RMSC],dbo.RollingSalesBandRM (u.Rolling_12)as SalesBandinginto #banding FROM [FDMS].[dbo].[Geo_PCA_Sellers] gINNER JOIN #Update uON u.NewPostcode = g.PCA--select * from #banding--drop table #banding ----------------------------------------------------select #banding.DBA_Name,#banding.ParentID,#banding.Post_Code,#banding.Rolling_12,#banding.RMSC,#banding.SalesBanding,case when Salesbanding in ('50M to 100+')then 'R05'When Salesbanding in ('2M to 5M')then 'R16'else #banding.RMSC end as NewRMSC Into #testFrom #banding--select * from #test--drop table #test----------------------------------------update testset NewRMSC = case when rn % 2 = 0 then 'R16' else 'R15' endfrom(select NewRmsc, rn = row_number() over (order by rolling_12 desc)from #testwhere NewRMSC = 'R16') testnow i have updated the table, how can i choose what Specific columns i want from that update table ? for eg if i put select * from #testit produce the following DBA_Name ,ParentID, Post_Code, Rolling_12, RMSC, SalesBanding ,NewRMSCAll i need to select is DBA_Name ,ParentID, Post_Code, Rolling_12, SalesBanding ,NewRMSC |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-12 : 07:16:26
|
instead of SELECT *just doSELECT DBA_Name ,ParentID, Post_Code, Rolling_12, SalesBanding ,NewRMSC from #test Too old to Rock'n'Roll too young to die. |
 |
|
|
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2012-09-12 : 07:20:49
|
| :) cheers buddy ! |
 |
|
|
|
|
|
|
|