SQL query
-
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.:) -
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.:)Using which language(s) ?
-
Using which language(s) ?
-
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[^]
-
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.:)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
-
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.:)