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
 Transact-SQL (2000)
 Using SELECT statements with SET command

Author  Topic 

Sanchit297
Starting Member

16 Posts

Posted - 2010-05-24 : 13:11:05
Hi,

I need to assign output from SELECT statement to a declared variable. The statement mentioned below works with no issues.


SET @TrackCount = (select count(events) from import_temp where @Id= Id)


Now I need to assign the data retrieved from the below mentioned SELECT statements.


SELECT MAX(ScanDateTime) FROM import_temp WHERE @Id = Id

SELECT MAX(DataDateTime) FROM import_temp WHERE @Id = Id

SELECT max(convert(nvarchar,DataDateTime - ScanDateTime,108))
FROM import_temp
WHERE @Id = Id

SELECT convert(nvarchar, convert(datetime, avg(convert(real, DataDateTime))), 108 )
FROM import_temp
WHERE @Id = Id


Is it possible to store the values returned from the above SELECT statements using SET command ( as shown for 1st SELECT stat above) ??

Thanks,
Sanchit

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-24 : 13:11:52
SELECT @var1 = MAX...

SELECT @var2 = CONVERT...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Sanchit297
Starting Member

16 Posts

Posted - 2010-05-25 : 01:56:52
Thanks for the response tkizer. That worked!!

I also have 2 fields - ScanTime and DataTime. Now I want manipulate the these 2 fields to get AverageTime something like..

(Sum of timestamps for ScanTime + Sum of timstamp for DataTime)% (Total events)


ScanTime and DataTime are DATETIME type and Total Events is INT.
Eg..
ScanTime - 2010-05-25 03:45:10
DataTime - 2010-06-23 09:50:09

AverageTime field should be in hh24:mi:ss format.

How can it be achieved ?

Thanks,
Sanchit
Go to Top of Page
   

- Advertisement -