June 29, 2009 at 9:21 pm
Hi all,
I would like to print each record in the result set, is using CURSOR a proper approach?
Exmaple, I want a list of Customer ID and Name
-- * Print Customer ID and Name --
USE Northwind
DECLARE @CustID NCHAR(5)
DECLARE @CustName NVARCHAR(40)
DECLARE myCursor CURSOR FOR
SELECT CustomerID, CompanyName FROM Customers
OPEN myCursor
FETCH NEXT FROM myCursor INTO @CustID, @CustName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @CustID + ' - ' + @CustName
FETCH NEXT FROM myCursor INTO @CustID, @CustName;
END
CLOSE myCursor
DEALLOCATE myCursor
Kindly advise, thanks.
June 29, 2009 at 9:29 pm
What's wrong with just doing this:
SELECT CustomerID, CompanyName FROM Customers
June 29, 2009 at 10:08 pm
I wanted the result in text format, and with some additional text also.
June 29, 2009 at 10:13 pm
Thanks, just found that by setting Results to Text will do. 😀
June 29, 2009 at 10:13 pm
you can cast or convert the data in text format after adding additional text.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply