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 2000 Forums
 SQL Server Development (2000)
 Assign distinct value to local variable

Author  Topic 

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2006-07-18 : 23:37:58
Hi

I could not get this to work.

Declare @ColDate as Varchar(15)
Select @ColDate = Distinct(TransDate)as TD from tblDemo

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-19 : 00:02:19
"select distinct transdate from tlbdemo" may return multiple records and assigning to a variable will mean you only have the last record in the variable. Is this what you want ?


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-19 : 00:42:29
This will assign the only one TransDate to the variable @ColDate eventhough there are several distinct TransDate return.
Is this what you want ?
Declare @ColDate as Varchar(15)
Select Distinct @ColDate = TransDate from tblDemo


Or do you want the min or max transdate ?
Declare @ColDate as Varchar(15)
Select @ColDate = min(TransDate) from tblDemo





KH

Go to Top of Page

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2006-07-19 : 01:18:26
Thanks
Go to Top of Page
   

- Advertisement -