The cursor seems useless in the code you've provided. You create the
cursor, fetch the first value, and then close the cursor. Why not just
select the value you want into the variables?
If your question is how to default a zero value if it's not found, you
can just put that in an IF statement after the variable assignment, or
in an ISNULL wrapped around the select statement.
Martin Sloan
Empathica Inc.
2121 Argentia Road, Suite 200
Mississauga ON L5N 2X4
Tel 905.542.9001 ex. 219
Fax 905.542.8170
www.empathica.com
This communication is confidential and may be legally privileged. If you
are not the intended recipient, (i) please do not read or disclose to
others, (ii) please notify the sender by reply mail, and (iii) please
delete this communication from your system. Failure to follow this
process may be unlawful. Thank you for your cooperation.
-----Original Message-----
From: Anwar Sonday
[mailto:mssqldba-ezmlmshield-x76690682.[Email address protected]
Sent: Thursday, March 29, 2007 3:40 AM
To: LazyDBA Discussion
Subject: RE: Next Number - Urgent
-----Original Message-----
From: Muhammad Siddique
[mailto:mssqldba-ezmlmshield-x90355570.[Email address protected]
Sent: 29 March 2007 09:24 AM
To: LazyDBA Discussion
Subject: Next Number - Urgent
Dear All,
I have made below routine for getting next number where cursor is
created.
Is there any way short way like if exist(select..) through I can get
next number?
Please help.
DECLARE @FISPRD AS VARCHAR(6)
SET @FISPRD = @FISNO + LEFT(@PRD, 2)
DECLARE @VNORETURN INT
DECLARE @VNO INT
DECLARE @NTOCVNO VARCHAR(4)
SET @VNORETURN = 0
--DECLARE CURSOR
DECLARE VNO_CURSOR CURSOR LOCAL SCROLL STATIC
FOR
SELECT RIGHT(VNO,4) FROM GLTRAN_MF WHERE BRNCODE = @BRNCODE AND VTYPE =
@VTYPE AND
LEFT(VNO,5) = @FISPRD ORDER BY VNO DESC
OPEN VNO_CURSOR
FETCH NEXT FROM VNO_CURSOR INTO @NTOCVNO
IF @@CURSOR_ROWS = 0
SET @NTOCVNO = '0'
CLOSE VNO_CURSOR
DEALLOCATE VNO_CURSOR
--CLOSE CURSOR
SET @VNO = @NTOCVNO
SELECT @NTOCVNO = DBO.NTOC(@VNO+1)
SET @PRD = LEFT(@PRD,2) + @NTOCVNO
Regards,
Siddique
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
---------------------------------------------------------------------
TO REPLY TO EVERYBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
To post a dba job: http://jobs.lazydba.com
To subscribe : http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html
Disclaimer
http://www.shoprite.co.za/disclaimer.html
---------------------------------------------------------------------
TO REPLY TO EVERYBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
To post a dba job: http://jobs.lazydba.com
To subscribe : http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html
MS Sql Server LazyDBA home page