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 |
|
itmasterw
Yak Posting Veteran
90 Posts |
Posted - 2009-11-11 : 12:15:05
|
| Hi,I have this code that tell me is a coumn changed. Tyhan someone helped me with here. Thank you And it works great. The only thing is that it gives the first column the name = "ColumnAChangeYesNo" but the other coumns does not have a name. How can I gieve each column a name here? (I would like something like colA, colB, colC).Thank youALTER PROCEDURE dbo.ComparProc ASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;Select ColumnAChangeYesNo =Case WHEN a.text1 <> b.text1 THEN 'Yes' ELSE 'No' END,Case WHEN a.text2 <> b.text2 THEN 'Yes' ELSE 'No'END,Case WHEN a.text3 <> b.text3 THEN 'Yes' ELSE 'No'ENDFROM tbl_reportA aINNER JOIN tbl_reportB bon a.text1 = b.text1ENDITM |
|
|
itmasterw
Yak Posting Veteran
90 Posts |
Posted - 2009-11-11 : 12:19:32
|
| I solved this thank youITM |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-11-11 : 12:20:13
|
quote: Originally posted by itmasterw Hi,I have this code that tell me is a coumn changed. Tyhan someone helped me with here. Thank you And it works great. The only thing is that it gives the first column the name = "ColumnAChangeYesNo" but the other coumns does not have a name. How can I gieve each column a name here? (I would like something like colA, colB, colC).Thank youALTER PROCEDURE dbo.ComparProc ASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;Select ColumnAChangeYesNo =Case WHEN a.text1 <> b.text1 THEN 'Yes' ELSE 'No' END,<second col name here>=Case WHEN a.text2 <> b.text2 THEN 'Yes' ELSE 'No'END,<third col name here>=Case WHEN a.text3 <> b.text3 THEN 'Yes' ELSE 'No'ENDFROM tbl_reportA aINNER JOIN tbl_reportB bon a.text1 = b.text1ENDITM
like above |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-11 : 12:21:17
|
Select ColumnAChangeYesNo =CaseWHEN a.text1 <> b.text1 THEN 'Yes'ELSE 'No' END,Col1=CaseWHEN a.text2 <> b.text2 THEN 'Yes'ELSE 'No'END,Col2=CaseWHEN a.text3 <> b.text3 THEN 'Yes'ELSE 'No'ENDFROM tbl_reportA aINNER JOIN tbl_reportB bon a.text1 = b.text1END No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-11 : 12:21:48
|
 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2009-11-11 : 12:48:07
|
For what it is worth, you should be using the AS Clause to name/rename columns. Per BOL: quote: The AS clause is the syntax defined in the ISO standard for assigning a name to a result set column. This is the preferred syntax to use in Microsoft SQL Server.
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|