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 |
ram.marella
Starting Member
15 Posts |
Posted - 2008-06-03 : 15:50:19
|
All,I have a problem with SQL query.my situation is as followsTABLE A:Col1 Col2-------------Val1 AVal2 AVal3 CVal4 DVal5 DIn this case i want output like as follows:I want to do group by on Col2 for specific items like where Col2<>'D' and for rest of the colmns i dont want to do group by.The final output should be as follows.Col1 Col2------------Val1 A (means min(Col1)when doing group by)Val3 CVal4 DVal5 DCan any one shed some lights on this and if not possible wih Group by then is there any alternative?Thanks in advanceThanks-----------------Ram MCP |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-06-03 : 15:52:59
|
SELECT MIN(Col1) AS Col1, Col2FROM YourTableWHERE Col2 <> 'D'GROUP BY Col2UNIONSELECT Col1, Col2FROM YourTableWHERE Col2 = 'D'Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
ram.marella
Starting Member
15 Posts |
Posted - 2008-06-03 : 16:28:35
|
Thank you so much, in addition to that i have another problem like as follows:I have to insert the data from TableB to TableA as follows:TableA:Col1 Col2 Col3---------------TableBCol1 Col2 Col3-------------1 2 false3 4 truei have ti use insert abouve two rows into TableA based on the TableB Col3 value. if Col3 TRUE in TableB then insert 1 in tableA, if Col3 in TableB Flase insert 0 in TableA.Thanks-----------------Ram MCP |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-04 : 00:18:13
|
quote: Originally posted by ram.marella Thank you so much, in addition to that i have another problem like as follows:I have to insert the data from TableB to TableA as follows:TableA:Col1 Col2 Col3---------------TableBCol1 Col2 Col3-------------1 2 false3 4 truei have ti use insert abouve two rows into TableA based on the TableB Col3 value. if Col3 TRUE in TableB then insert 1 in tableA, if Col3 in TableB Flase insert 0 in TableA.Thanks-----------------Ram MCP
Have you tried this yourself before asking? Then show us what you've tried till now.A simple query will provide you solution for your problem. |
 |
|
|
|
|