Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

whats wrong with this statement using a cursor?

Status
Not open for further replies.

lak201

Programmer
Oct 6, 2004
10
US
hi, i am new to sql , so pls forgive if this is too naive

DECLARE @CUSIP VARCHAR(50)
--set @cusip='abc us equity'
DECLARE @DECLARE VARCHAR(10)
--set @dealer='gsco'
DECLARE @BID FLOAT
--set @bid=50
DECLARE @ASK FLOAT
--set @ask=50
DECLARE @STOCK_REF_PX FLOAT
--set @stock_ref_px=50
DECLARE @GET5Y_REF_PX FLOAT
--set @get5y_ref_px=0.05
DECLARE @UPDATE_DATE DATETMIE
--set @update_date='10/06/04'

DECLARE @INST_ID INT
DECLARE @DEALER_ID INT
DECLARE @MARK_ID INT

SET @DEALER_ID = (SELECT DEALER_ID FROM HEDGEHOG_DEALERS WHERE DEALER_NAME = @DEALER)
SET @MARK_ID = (SELECT MAX(MARK_ID)+1 FROM HEDGEHOG_MARKS)

DECLARE CR_INST_ID CURSOR LOCAL FORWARD_ONLY FAST_FORWARD READ_ONLY
FOR SELECT DISTINCT INST_ID
FROM HEDGEHOG_INSTRUMENTS
WHERE INST_ID IN
(SELECT INST_ID
FROM HEDGEHOG_CUSIPS
WHERE CUSIP=@CUSIP)
FOR {READ ONLY}
OPEN CR_INST_ID
FETCH NEXT FROM CR_INST_ID INTO @INST_ID
WHILE @@FETCH_STATUS
BEGIN
INSERT INTO HEDGEHOG_MARKS (INST_ID, DEALER_ID, BID, ASK, STOCK_REF_PX, GET5Y_REF_PX, UPDATE_DATE, MARK_ID)
VALUES (@INST_ID,@DEALER_ID,@BID,@ASK,@STOCK_REF_PX,@GET5Y_REF_PX,@UPDATE_DATE,@MARK_ID)
SET @MARK_ID=MARK_ID+1
END
CLOSE CR_INST_ID
DEALLOCATE CR_INST_ID

 
Replace this:
DECLARE @DECLARE VARCHAR(10)
By this:
DECLARE @DEALER VARCHAR(10)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
sorry , the 3rd line should be :

DECLARE @DEALER VARCHAR(10)
 
So, what is your prob ?
Any error message ? Unexpected behaviour ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
this is the message i get in the query analyzer:

[Microsoft][ODBC SQL Server Driver]Syntax error or access violation.

thanks
 
You may get more accurate replies in the SQL Server forum.
Seems your code must be inside a stored procedure.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top