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. SQL query

SQL query

Scheduled Pinned Locked Moved Database
databasequestioncareer
6 Posts 5 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.
  • J Offline
    J Offline
    John theKing
    wrote on last edited by
    #1

    Friends, consider the following query: select id, name, nick from blahtable where salary=2000 As you can see above i selected three fields from a table. Assume that the query returns only one record. Now i want the values of three fields returned, to be assigned in variables and then i want to print the values of these variables. How can i do so.:)

    J G S 3 Replies Last reply
    0
    • J John theKing

      Friends, consider the following query: select id, name, nick from blahtable where salary=2000 As you can see above i selected three fields from a table. Assume that the query returns only one record. Now i want the values of three fields returned, to be assigned in variables and then i want to print the values of these variables. How can i do so.:)

      J Offline
      J Offline
      John Honan
      wrote on last edited by
      #2

      Using which language(s) ?

      L 1 Reply Last reply
      0
      • J John Honan

        Using which language(s) ?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        SQL-Server

        J 1 Reply Last reply
        0
        • L Lost User

          SQL-Server

          J Offline
          J Offline
          John Honan
          wrote on last edited by
          #4

          Well, if you are doing this purely in SQL Server, then you can go into Query Analyser, run the SELECT query, and print the grid from there. If you want to start assigning return values to variables and formatting printout (and perhaps changing the SELECT criteria), then you have to look at doing this from a client-side tool, such as VB.NET, or Crystal Reports. Alternatively, you may be able to write a SQL Stored Procedure which takes criteria, and outputs the 3 fields you need (this gets complicated if you want to send the three fields directly to a printer from a stored procedure) Is this part of a user application you're developing, or is it a once-off ad-hoc type query you're running? John. www.silveronion.com[^]

          1 Reply Last reply
          0
          • J John theKing

            Friends, consider the following query: select id, name, nick from blahtable where salary=2000 As you can see above i selected three fields from a table. Assume that the query returns only one record. Now i want the values of three fields returned, to be assigned in variables and then i want to print the values of these variables. How can i do so.:)

            G Offline
            G Offline
            greg lynch _nj_
            wrote on last edited by
            #5

            I believe this may be the solution --Declare the Necessary Variables DECLARE @ID AS int, @Name AS nvarChar(15), @Nick AS nvarChar(15) --Incorporate those Variables --Into the Select Statement SELECT @ID = id, @Name = name, @Nick = nick FROM blahtable WHERE salary = 2000 PRINT @ID PRINT @Name PRINT @Nick Buy the Book 'Advanced Transact-SQL for SQL Server 2000' by Itzak Bengan and Tom Moreau, If you plan on working with SQL, it will change your life ...just kidding but its a powerfull book Gregory J Lynch Hack

            1 Reply Last reply
            0
            • J John theKing

              Friends, consider the following query: select id, name, nick from blahtable where salary=2000 As you can see above i selected three fields from a table. Assume that the query returns only one record. Now i want the values of three fields returned, to be assigned in variables and then i want to print the values of these variables. How can i do so.:)

              S Offline
              S Offline
              si_69
              wrote on last edited by
              #6

              try this declare @id int declare @name varchar(30) declare @nick varchar(30) select @id = id, @name = name, @nick = nick from blahtable where salary=2000 print @id print @name print @nick Si ;)

              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