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 |
Ehtesham Siddiqui
Starting Member
10 Posts |
Posted - 2011-11-11 : 05:48:55
|
Hi,Im using Sql server 2005,I have two tables.Say table1 and table2All the data is fetched from Table1 only.table two is used for confirmation.Like There is a Column say StudentMobile in table2 which hold the values either True or False.table 2 also has a Registration Number Column,now if this StudentMobile value is true then only the data of that particular student should be fetched from Table1.Please Have a look at my Query.I have successfully done with using single Case Statement but m not able to aplly multiple Cases.Please Guide.SELECT Table1.RegNo,Table1.MobileNo,case when Table2.UseStudentMobile='True' then Table1.StudentMobileend //Im having issue when i use another Case Herecase when Table2.ParentStudentMobile='True' then Table1.ParentMobileend FROM Table1 INNER JOINTable2 ON Table1.RegNo = Table2.Regno The code in Bold is the Line that is giving me Error.If i remove that case than im not getting any error.SMKSoftware EngineerIndia |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-11-11 : 05:52:10
|
SELECT Table1.RegNo,Table1.MobileNo,case when Table2.UseStudentMobile='True' then Table1.StudentMobileend ,case when Table2.ParentStudentMobile='True' then Table1.ParentMobileend FROM Table1 INNER JOINTable2 ON Table1.RegNo = Table2.Regnoor maybe you wantSELECT Table1.RegNo,Table1.MobileNo,case when Table2.UseStudentMobile='True' then Table1.StudentMobilewhen Table2.ParentStudentMobile='True' then Table1.ParentMobileend FROM Table1 INNER JOINTable2 ON Table1.RegNo = Table2.RegnoIs ParentMobile on Table1 or Table2?==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
Devart
Posting Yak Master
102 Posts |
Posted - 2011-11-11 : 05:55:45
|
Hello,Try it:SELECT Table1.RegNo,Table1.MobileNo,CASE WHEN Table2.UseStudentMobile='True' THEN Table1.StudentMobileEND AS StudentMobile,CASE WHEN Table2.ParentStudentMobile='True' THEN Table1.ParentMobileEND AS ParentMobileFROM Table1 INNER JOIN Table2 ON Table1.RegNo = Table2.RegnoDevart,SQL Server Tools:dbForge Data StudiodbForge Schema ComparedbForge Data ComparedbForge SQL Complete |
|
|
|
|
|
|
|