Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1067273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:08:12+00:00 2026-05-16T20:08:12+00:00

i was just working with cursor in SQL 2008 but i face some problems.

  • 0

i was just working with cursor in SQL 2008 but i face some problems.
the first is that with the line i declared the cursor every time i execute the query it gives me an error. which says the cursor with such a name already exists. i want to offer me a way that if the cursor exists do not create it and if it is not defined yet sql creates it. i ad that i have closed and deallocated the cursor at the end of the code but the problem still resides.

declare c1 cursor fast_forward for select CustomerID, [Customer Name], [Product Name],  
Maximum from favorit;
open c1
fetch next from c1 into @custID, @custName, @prodName, @max;
while @@FETCH_STATUS = 0
begin
PRINT @CustID, @custName;
fetch next from c1 into @custID, @custName, @prodName, @max;
end
close c1
deallocate c1

i have another question about print function in sql with the line below

PRINT @CustID, @custName;

is invalid?? what is the syntax in SQL and how can we print several variables in SQL, if it is possible please suggest a way to con cat two variables and some strings between them for example like below:

 print @custID + 'this is the customer name' + @custName + 'etc'

just one other question for each line i print i want to print the number of line for example some thing like this:
1 customer name customer id …
2 customer name customer id …
…
end of cursor.
how would you offer to implement and print those numbers in the while statement of cursor
?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:08:13+00:00Added an answer on May 16, 2026 at 8:08 pm

    It’s not really clear what you’re trying to do. Why not just run your query to get all the results in one go, and then use your client code to format and present the data?

    select CustomerID, [Customer Name], [Product Name], Maximum from favorit
    

    You can use the ROW_NUMBER() function to add row numbers if you want, or number them in the client application when you present the output.

    Next, PRINT is a statement, not a function. It can print only one string, so you need to build and then PRINT the string. Your second example might actually work, but you will have to handle any different data types:

    print cast(@custID as varchar(10)) + 'this is the customer name' + cast(@custName as varchar(100)) + 'etc'  
    

    Finally, formatting and printing data directly from TSQL is usually a sign that you’re doing something wrong. The usual approach is to return a result set to a client application and let the client application format it, print it, convert it to PDF or whatever. Your application could be a small Perl script, a complete reporting solution, or anything in between, but PRINT is not really a good mechanism for presenting data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started working with dependency injection for the first time and I am
I just started working on my first Visual Studio project, and I imported all
I just started working on a website that will help people understand what rappers
I'm writing a function in SQL that we can use to validate First/Middle/Last names
I currently am working on a legacy application and have inherited some shady SQL
I've been working at this all day, and I'm really close but just can't
I have the following form working just fine in Chrome, but doesn't seem to
I am just working on creating a matrix report in SSRS and when I
I have the following JQuery function about a range slider . It's just working
Just started working with .NET and MVC(1). I'm having a problem wherein in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.