Tpaul_10
asked on
Select Statement
Experts,
Here is the SQL I am running and no problems with the SQL.
select T1.Column1,T2.Column3,coun t(T1.Colum n6) as TestColumn1
from Table T1
inner join Tablle2 T2
on T1.Column1 = T2.Column1
where T1.Column1 > 'myvalue'
group by T1.Column1,T2.Column3
union
select T1.Column1,T3.Column3,coun t(T1.Colum n6) as TestColumn1
from Table T1
inner join TempTablle T3
on T1.Column1 = T3.Column1
where T3.Column3 > 'myvalue'
group by T1.Column1,T3.Column3
I need to add one more column to my select and the output or the result of the newcolumn is like following.
C1 C2 C3 NewColumn
A 100 1 1
B 200 0 2
C 500 1 3
D 720 1 4
if my select gives 2 rows, newcolumns values should be 1 and 2
if my select gives 10 rows, newcolumns values should be 1 to 10
Thanks in advance and let me know if the question is not clear.
Here is the SQL I am running and no problems with the SQL.
select T1.Column1,T2.Column3,coun
from Table T1
inner join Tablle2 T2
on T1.Column1 = T2.Column1
where T1.Column1 > 'myvalue'
group by T1.Column1,T2.Column3
union
select T1.Column1,T3.Column3,coun
from Table T1
inner join TempTablle T3
on T1.Column1 = T3.Column1
where T3.Column3 > 'myvalue'
group by T1.Column1,T3.Column3
I need to add one more column to my select and the output or the result of the newcolumn is like following.
C1 C2 C3 NewColumn
A 100 1 1
B 200 0 2
C 500 1 3
D 720 1 4
if my select gives 2 rows, newcolumns values should be 1 and 2
if my select gives 10 rows, newcolumns values should be 1 to 10
Thanks in advance and let me know if the question is not clear.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
select Columns 1...4, Rownumber()(order by columns1)
from (your query)
from (your query)
Let's hope, they are at least using SQL Server 2005 (if not 2008).