Set variable values from queried data
-
I am trying to retrieve the Earliest and latest Dates and prices Using the following code, which works fine. I need to enter the values to a variable as seen below, which does not work can someone please help Thanks in advance, Michael USE "Sales" GO SET NOCOUNT ON; DECLARE @dtEarliestDate DATETIME, @fltEarliestPrice REAL, @dtLatestDate DATETIME, @fltLatestPrice REAL SELECT * FROM ( SELECT TOP 1 dtDateTime, fltPrice FROM Customers ORDER BY dtDateTime DESC UNION ALL SELECT TOP 1 dtDateTime, fltPrice FROM Customers ORDER BY dtDateTime ASC ) AS B --SET @dtEarliestDate = B.dtDateTime --SET @dtLatestDate = B.dtDateTime --SET @fltLatestPrice = B.fltPrice --SET @fltEarliestPrice = B.fltPrice
-
I am trying to retrieve the Earliest and latest Dates and prices Using the following code, which works fine. I need to enter the values to a variable as seen below, which does not work can someone please help Thanks in advance, Michael USE "Sales" GO SET NOCOUNT ON; DECLARE @dtEarliestDate DATETIME, @fltEarliestPrice REAL, @dtLatestDate DATETIME, @fltLatestPrice REAL SELECT * FROM ( SELECT TOP 1 dtDateTime, fltPrice FROM Customers ORDER BY dtDateTime DESC UNION ALL SELECT TOP 1 dtDateTime, fltPrice FROM Customers ORDER BY dtDateTime ASC ) AS B --SET @dtEarliestDate = B.dtDateTime --SET @dtLatestDate = B.dtDateTime --SET @fltLatestPrice = B.fltPrice --SET @fltEarliestPrice = B.fltPrice
This SQL works for me ...
begin
declare @max_date datetime
set @max_date = (select max(creation_date) from fsformula)
print @max_date
end
-
I am trying to retrieve the Earliest and latest Dates and prices Using the following code, which works fine. I need to enter the values to a variable as seen below, which does not work can someone please help Thanks in advance, Michael USE "Sales" GO SET NOCOUNT ON; DECLARE @dtEarliestDate DATETIME, @fltEarliestPrice REAL, @dtLatestDate DATETIME, @fltLatestPrice REAL SELECT * FROM ( SELECT TOP 1 dtDateTime, fltPrice FROM Customers ORDER BY dtDateTime DESC UNION ALL SELECT TOP 1 dtDateTime, fltPrice FROM Customers ORDER BY dtDateTime ASC ) AS B --SET @dtEarliestDate = B.dtDateTime --SET @dtLatestDate = B.dtDateTime --SET @fltLatestPrice = B.fltPrice --SET @fltEarliestPrice = B.fltPrice
you need to look at using output parameters, further reading MSDN: Using a Stored Procedure with Output Parameters[^]
Nagy Vilmos wrote:
And eat bacon. Bacon's real important for 'puters.
-
I am trying to retrieve the Earliest and latest Dates and prices Using the following code, which works fine. I need to enter the values to a variable as seen below, which does not work can someone please help Thanks in advance, Michael USE "Sales" GO SET NOCOUNT ON; DECLARE @dtEarliestDate DATETIME, @fltEarliestPrice REAL, @dtLatestDate DATETIME, @fltLatestPrice REAL SELECT * FROM ( SELECT TOP 1 dtDateTime, fltPrice FROM Customers ORDER BY dtDateTime DESC UNION ALL SELECT TOP 1 dtDateTime, fltPrice FROM Customers ORDER BY dtDateTime ASC ) AS B --SET @dtEarliestDate = B.dtDateTime --SET @dtLatestDate = B.dtDateTime --SET @fltLatestPrice = B.fltPrice --SET @fltEarliestPrice = B.fltPrice