How do I set a variable to the result of select query without using a stored procedure?
I want to do something like: OOdate DATETIME
SET OOdate =
You can use something like
SET @cnt = (SELECT COUNT(*) FROM User)
or
SELECT @cnt = (COUNT(*) FROM User)
For this to work the SELECT must return a single column and a single result and the SELECT statement must be in parenthesis.
Edit: Have you tried something like this?
DECLARE @OOdate DATETIME
SET @OOdate = Select OO.Date from OLAP.OutageHours as OO where OO.OutageID = 1
Select COUNT(FF.HALID)
from Outages.FaultsInOutages as OFIO
inner join Faults.Faults as FF
ON FF.HALID = OFIO.HALID
WHERE @OODate = FF.FaultDate
AND OFIO.OutageID = 1