SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 sql statement(logic)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kond.mohan
Posting Yak Master

India
138 Posts

Posted - 05/30/2012 :  05:36:34  Show Profile  Reply with Quote


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
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 05/30/2012 :  07:29:36  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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

India
227 Posts

Posted - 05/30/2012 :  07:38:51  Show Profile  Reply with Quote
Please post some sample data to work with.

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000