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 |
|
CoVS
Starting Member
1 Post |
Posted - 2010-07-14 : 11:07:08
|
Apologys - I am VERY new to this SQL nonsense and so this is probably a very silly question!I want to be able to name a column created from my query.Query is:select A.OrigRef, A.DisplayName, A.ExtCode, count(CalcId)from OrigRefView A, CalcView B where A.OrigRef = B.NewRef and A.OrigRef like 'AB%'group by A.OrigRef, A.DisplayName, A.ExtCodeorder by A.SusRefand it returns the Count in "column4"Is there a way I can get the query to output a different column name without creating a whole new table (i.e. not by creating a new table for my query output and then running a new procedure at the end to rename the column...)?i.e. I want "column4" to read "CountofCalId"Many thanks!   |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-07-14 : 11:11:10
|
| select A.OrigRef, A.DisplayName, A.ExtCode, count(CalcId) as CountOfCalcIdfrom OrigRefView A, CalcView B where A.OrigRef = B.NewRef and A.OrigRef like 'AB%'group by A.OrigRef, A.DisplayName, A.ExtCodeorder by A.SusRefJimEveryday I learn something that somebody else already knew |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-07-14 : 11:12:24
|
select A.OrigRef, A.DisplayName, A.ExtCode, count(CalcId) as CountofCalIdfrom OrigRefView A, CalcView B where A.OrigRef = B.NewRef and A.OrigRef like 'AB%'group by A.OrigRef, A.DisplayName, A.ExtCodeorder by A.SusRef 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 - 2010-07-14 : 11:12:54
|
 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-07-14 : 11:21:01
|
Yes, but you took the extra time to put the correction in bold face JimEveryday I learn something that somebody else already knew |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-07-16 : 11:52:36
|
| Note that all aggregates,usage of functions over a column and case expression by default wont produce a column nameMadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-07-17 : 09:49:19
|
Also you can't specify a column (A.SusRef) in ORDER BY, unless it is part of the GROUP BY or the aggregate functionselect A.OrigRef, A.DisplayName, A.ExtCode, count(CalcId) as CountofCalIdfrom OrigRefView A, CalcView B where A.OrigRef = B.NewRef and A.OrigRef like 'AB%'group by A.OrigRef, A.DisplayName, A.ExtCodeorder by A.SusRef KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|