Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to convert Numeric to Character in CURSOR

Author  Topic 

bharatagraj
Starting Member

6 Posts

Posted - 2005-08-19 : 14:03:00
Hi All there -
I want to show the o/p of a cursor on a single line. There is a numeric variable that needs to be clubed with the character variable. If I use char() the o/p is not right.
How do I do that?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-08-19 : 15:18:56
Please post your code as well as show us the output that you expect as I don't understand what you are asking for.

Tara
Go to Top of Page

bharatagraj
Starting Member

6 Posts

Posted - 2005-08-19 : 15:55:07
MY CODE IS -

declare @name char(30)
declare @homebase char(40)
declare @style char(20)
declare @artist_id int
declare Artist_cursor cursor
for select * from artists
open Artist_cursor
fetch Artist_cursor into @name, @homebase, @style, @artist_id
while (@@fetch_status = 0)
Begin
Print @name + @homebase + @style + char(@artist_id)
fetch Artist_cursor into @name, @homebase, @style, @artist_id
end
close Artist_cursor
deallocate Artist_cursor

THE O/P is

Server: Msg 16915, Level 16, State 1, Line 6
Crowded House New Zealand Pop 
Dave Matthews Band Charlottesville Rock 
Edward MacDowell U.S.A. Classical 
Mary Chapin-Carpenter Nashville Country 
Maurice Ravel France Classical 
Oingo Boingo Los Angeles Pop 
Soul Ascylum Minneapolis Rock 
Vince Gill Nashville Country 
------
Here when I converted to char() you can see the o/p as 
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-08-19 : 16:07:22
Lookup CHAR() in Books On-Line. It does now do what you think it does. You need to use CONVERT to convert a numeric value into a string representation.

On top of that, why are you using a cursor?
Go to Top of Page
   

- Advertisement -