Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Set variable values from queried data

Set variable values from queried data

Scheduled Pinned Locked Moved Database
saleshelp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MAW30
    wrote on last edited by
    #1

    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

    D S S 3 Replies Last reply
    0
    • M MAW30

      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

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      This SQL works for me ...

      begin

      declare @max_date datetime

      set @max_date = (select max(creation_date) from fsformula)

      print @max_date

      end

      1 Reply Last reply
      0
      • M MAW30

        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

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • M MAW30

          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

          S Offline
          S Offline
          SilimSayo
          wrote on last edited by
          #4

          I haven't tested this but try it .

          SELECT TOP 1 @dtLatestDate=dtDateTime, @fltLatestPrice =fltPrice FROM Customers ORDER BY dtDateTime DESC
          SELECT TOP 1 @dtEarliestDate =dtDateTime, @fltEarliestPrice=fltPrice FROM Customers ORDER BY dtDateTime ASC

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups