Click here to Skip to main content
15,914,327 members
Home / Discussions / Database
   

Database

 
QuestionDST Implementation Pin
ramdil4-Sep-07 22:46
ramdil4-Sep-07 22:46 
AnswerRe: DST Implementation Pin
Vasudevan Deepak Kumar4-Sep-07 23:44
Vasudevan Deepak Kumar4-Sep-07 23:44 
QuestionSql server Date Diff Pin
Praveen0294-Sep-07 21:35
Praveen0294-Sep-07 21:35 
AnswerRe: Sql server Date Diff Pin
Frank Kerrigan5-Sep-07 1:01
Frank Kerrigan5-Sep-07 1:01 
AnswerRe: Sql server Date Diff Pin
Michael Potter5-Sep-07 5:48
Michael Potter5-Sep-07 5:48 
AnswerRe: Sql server Date Diff Pin
Frank Kerrigan5-Sep-07 22:56
Frank Kerrigan5-Sep-07 22:56 
QuestionDistinct Select Query Pin
Shajeel4-Sep-07 21:23
Shajeel4-Sep-07 21:23 
AnswerRe: Distinct Select Query Pin
John-ph5-Sep-07 0:10
John-ph5-Sep-07 0:10 
Shajeel wrote:
I have table with three columns
col1, col2, col3
i need distinct values of col1 with any values in col2 and col3, eg if data is
1, A, A
1, B, B
2, C, C
i need my query to bring
1, A, A or 1, B, B (only one not both)
2, C, C


Don't know which version of SQL Server you are using. If 2000 then below written sql will solve the problem. If you are using 2005 then you can use ROW_NUMBER() instead of IDENTITY() and there is no need for #TempTable. If you are using 2000 and table has a Identity column then also there is no need for #TempTable.

Identity Column or the higher version (2005) will help you to do in single sql stmt...

select <br />
IDENTITY(INT, 1, 1)AS KeyCol, Col1, col2, col3 into #TempTable from tbldistinct<br />
<br />
select col1,col2,col3 from #TempTable B<br />
where (Select Count(*) from #TempTable A where A.col1 = B.col1 and A.KeyCol <= B.KeyCol) =1<br />
<br />
Drop Table #TempTable



Regards
J O H N Rose | [Rose]

"Even eagles need a push." David McNally

GeneralRe: Distinct Select Query Pin
Shajeel5-Sep-07 1:19
Shajeel5-Sep-07 1:19 
AnswerRe: Distinct Select Query Pin
Frank Kerrigan5-Sep-07 1:03
Frank Kerrigan5-Sep-07 1:03 
QuestionSql Ansi Pin
Clickok4-Sep-07 16:50
Clickok4-Sep-07 16:50 
AnswerRe: Sql Ansi Pin
Sathesh Sakthivel4-Sep-07 20:13
Sathesh Sakthivel4-Sep-07 20:13 
QuestionHow to filter column ? Pin
RichardBlare4-Sep-07 16:34
RichardBlare4-Sep-07 16:34 
AnswerRe: How to filter column ? Pin
John-ph5-Sep-07 0:42
John-ph5-Sep-07 0:42 
GeneralRe: How to filter column ? Pin
RichardBlare5-Sep-07 0:52
RichardBlare5-Sep-07 0:52 
GeneralRe: How to filter column ? Pin
Frank Kerrigan5-Sep-07 1:10
Frank Kerrigan5-Sep-07 1:10 
QuestionClear the Service Broker Queue Pin
FernandoMartin4-Sep-07 7:21
FernandoMartin4-Sep-07 7:21 
Questionreading xml by sql function Pin
Sachin Pimpale4-Sep-07 1:49
Sachin Pimpale4-Sep-07 1:49 
AnswerRe: reading xml by sql function Pin
WoutL4-Sep-07 1:54
WoutL4-Sep-07 1:54 
Questionhow t o call a stored procedure inside a stored procedure Pin
bhattiprolu4-Sep-07 0:59
bhattiprolu4-Sep-07 0:59 
AnswerRe: how t o call a stored procedure inside a stored procedure Pin
John-ph4-Sep-07 1:17
John-ph4-Sep-07 1:17 
GeneralRe: how t o call a stored procedure inside a stored procedure Pin
bhattiprolu4-Sep-07 1:26
bhattiprolu4-Sep-07 1:26 
GeneralRe: how t o call a stored procedure inside a stored procedure Pin
John-ph4-Sep-07 1:30
John-ph4-Sep-07 1:30 
GeneralRe: how t o call a stored procedure inside a stored procedure Pin
bhattiprolu4-Sep-07 1:34
bhattiprolu4-Sep-07 1:34 
GeneralRe: how t o call a stored procedure inside a stored procedure Pin
John-ph4-Sep-07 1:46
John-ph4-Sep-07 1:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.