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 2008 Forums
 Transact-SQL (2008)
 sql statement(logic)

Author  Topic 

kond.mohan
Posting Yak Master

213 Posts

Posted - 2012-05-30 : 05:36:34


i am executing sql query in ssms 2008 based on type

empno,
name,
salary
case when type=A then name end type1,
case when type=D then name end type2,
location

i got output like this

empno name sal type1 type2 date
1 dfl 100 ---- flsdf 19-08-2012
1 dfl 100 ---- dfggh 19-08-2012
1 dfl 100 k punct ------ 19-08-2012
1 dfl 100 k newyear ----- 19-08-2012


my expected out put is
empno name sal type1 type2 date
1 dfl 100 k punct flsdf 19-08-2012
1 dfl 100 k newyear dfggh 19-08-2012




nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-05-30 : 07:29:36
No you don't. query has locatio, result has date - not possible.
maybe
select
empno,
name,
salary
max(case when type=A then name end) type1,
max(case when type=D then name end) type2,
location
from tbl
group by empno,name sal,location

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

vinu.vijayan
Posting Yak Master

227 Posts

Posted - 2012-05-30 : 07:38:51
Please post some sample data to work with.

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page
   

- Advertisement -