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 2000 Forums
 Transact-SQL (2000)
 Using SELECT statements with SET command
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Sanchit297
Starting Member

India
16 Posts

Posted - 05/24/2010 :  13:11:05  Show Profile  Reply with Quote
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

USA
36648 Posts

Posted - 05/24/2010 :  13:11:52  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

India
16 Posts

Posted - 05/25/2010 :  01:56:52  Show Profile  Reply with Quote
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
  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