[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

why the output not shown

Posted on 2013-01-02
9
Medium Priority
?
256 Views
Last Modified: 2013-01-25
I have a MS  SQL 2008 script to try to print out an output from a table for each row. But it gave me * output. I compile the code, I don't see an error. can someone give me advice how to fix it?
0
Comment
Question by:wasabi3689
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Author Comment

by:wasabi3689
ID: 38738590
Attaching the source script here

DECLARE @device_id varchar(6);
DECLARE @counter decimal(10,0);
DECLARE @device_count INT;
DECLARE @lgroup_id varchar(20);

SET @counter = 1;
SET @device_count = 2;
SET @lgroup_id=6;

DECLARE devices_my CURSOR LOCAL for
  select device_id from devices where DEVICE_PIN between  5009166661 and 5009166662 order by device_id;

open devices_my;

SET IDENTITY_INSERT SCHED_ITEMS ON


while @COUNTER <= @device_count    
begin
    FETCH NEXT FROM devices_my INTO @device_id;
    IF @@FETCH_STATUS = 0

    PRINT 'Device ID: ' + @device_id + '    Counter: ' + convert(varchar(10),@counter)
   
    SET @COUNTER = @COUNTER + 1
end
CLOSE devices_my;
DEALLOCATE devices_my;

SET IDENTITY_INSERT SCHED_ITEMS OFF;
0
 
LVL 8

Expert Comment

by:venk_r
ID: 38738665
Is this the full code attached?Whats the output your'e getting.Did you say you just getting '*'
as output?
0
 

Author Comment

by:wasabi3689
ID: 38738683
yes, this is the full code, the output I got is

*
*
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 8

Accepted Solution

by:
venk_r earned 2000 total points
ID: 38738697
Your'e missing
 FETCH NEXT FROM devices_my INTO @device_id;
before the while loop starts.You need to mention the above before the while loop starts.
0
 

Author Comment

by:wasabi3689
ID: 38738716
Do you mean I should put this way instead?


FETCH NEXT FROM devices_my INTO @device_id;

while @COUNTER <= @device_count    
begin
   
    IF @@FETCH_STATUS = 0

    PRINT 'Device ID: ' + @device_id + '    Counter: ' + convert(varchar(10),@counter)
          

    SET @COUNTER = @COUNTER + 1
end
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38738720
Is there any reason you are writing the CURSOR that way and why are you doing the following?
SET IDENTITY_INSERT SCHED_ITEMS ON
,,,
SET IDENTITY_INSERT SCHED_ITEMS OFF;
0
 
LVL 8

Expert Comment

by:venk_r
ID: 38738722
Yes please .See below.
Also check to see if @device_id has NULL VALUE or any special character in it.

FETCH NEXT FROM devices_my INTO @device_id;

while @COUNTER <= @device_count    
begin
   
    IF @@FETCH_STATUS = 0

    PRINT 'Device ID: ' + @device_id + '    Counter: ' + convert(varchar(10),@counter)
         
   SET @COUNTER = @COUNTER + 1
 FETCH NEXT FROM devices_my INTO @device_id;

end
0
 

Author Comment

by:wasabi3689
ID: 38738743
print is just test statement. I have "Insert into..." statement instead.
0
 
LVL 12

Expert Comment

by:Saurabh Bhadauria
ID: 38739184
Change your statement like this....

DECLARE devices_my CURSOR LOCAL for
  select cast(device_id  as varchar(200))  from devices where DEVICE_PIN between  5009166661 and 5009166662 order by device_id;



I think there is some issue with implicit conversion...
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question