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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Trying to name my columns

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 you

ALTER PROCEDURE dbo.ComparProc
AS
BEGIN
-- 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'
END
FROM tbl_reportA a
INNER JOIN tbl_reportB b
on a.text1 = b.text1
END


ITM

itmasterw
Yak Posting Veteran

90 Posts

Posted - 2009-11-11 : 12:19:32
I solved this thank you

ITM
Go to Top of Page

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 you

ALTER PROCEDURE dbo.ComparProc
AS
BEGIN
-- 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'
END
FROM tbl_reportA a
INNER JOIN tbl_reportB b
on a.text1 = b.text1
END


ITM


like above
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-11 : 12:21:17
Select
ColumnAChangeYesNo =
Case
WHEN a.text1 <> b.text1 THEN 'Yes'
ELSE 'No'
END,
Col1=
Case
WHEN a.text2 <> b.text2 THEN 'Yes'
ELSE 'No'
END,
Col2=
Case
WHEN a.text3 <> b.text3 THEN 'Yes'
ELSE 'No'
END
FROM tbl_reportA a
INNER JOIN tbl_reportB b
on a.text1 = b.text1
END



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

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.
Go to Top of Page

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.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-12 : 01:48:49
quote:
Originally posted by Lamprey

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.



So as my points
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/09/09/should-alias-names-be-preceded-by-as-part-2.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -