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.
Author |
Topic |
gregdillon
Starting Member
2 Posts |
Posted - 2008-12-12 : 11:54:02
|
Hi All,This is my first attempt at a stored proc so please dont laugh. Basically i need a couple of bits of information inserted into 2 tables. Below is my "effort" of a proc. Naturally its getting loads of errors(See bottom). Any help would be much appreciated. **********************************CREATE PROCEDURE [dbo].[RQCurrencies](@RQCurrency char OUTPUT@RQCurrencyVal INT OUTPUT@RQCurrencyID INT OUTPUT@CounterID INT OUTPUT)ASSELECT @CounterID = CounterValue from tblcounterSELECT @RQCurrencyID = CounterValue from tblcounterSELECT @RQCurrencyVal = CurrencyVal from tblCurrencyIESELECT @RQCurrency = Currency from tblCurrencyIEUPDATE TBLCOUNTERSET CounterValue=CounterValue+1WHERE COUNTERID=1UPDATE TBLRQRatesSET RQCurrency = 'Euro' SET RQCurrencyVal = tblCurrencyIE.CurrencyVal Where tblCurrencyIE.CurrencyVal = 'Euro' SET RQCurrencyID = CounteriDUPDATE TBLRQRatesSET RQCurrency = 'Sterling' SET RQCurrencyVal = tblCurrencyIE.CurrencyVal Where tblCurrencyIE.CurrencyVal = 'Sterling' SET RQCurrencyID = CounteriDUPDATE TBLRQRatesSET RQCurrency = 'Dollar' SET RQCurrencyVal = tblCurrencyIE.CurrencyVal Where tblCurrencyIE.CurrencyVal = 'Dollar' SET RQCurrencyID = CounteriDRETURN @CounterIDRETURN @RQCurrencyRETURN @RQCurrencyValRETURN @RQCurrencyIDGO*********************************ErrorsServer: Msg 170, Level 15, State 1, Procedure RQCurrencies, Line 4Line 4: Incorrect syntax near '@RQCurrencyVal'.Server: Msg 137, Level 15, State 1, Procedure RQCurrencies, Line 10Must declare the variable '@CounterID'.Server: Msg 137, Level 15, State 1, Procedure RQCurrencies, Line 11Must declare the variable '@RQCurrencyID'.Server: Msg 137, Level 15, State 1, Procedure RQCurrencies, Line 12Must declare the variable '@RQCurrencyVal'.Server: Msg 170, Level 15, State 1, Procedure RQCurrencies, Line 21Line 21: Incorrect syntax near '='.Server: Msg 170, Level 15, State 1, Procedure RQCurrencies, Line 26Line 26: Incorrect syntax near '='.Server: Msg 170, Level 15, State 1, Procedure RQCurrencies, Line 31Line 31: Incorrect syntax near '='.Server: Msg 137, Level 15, State 1, Procedure RQCurrencies, Line 34Must declare the variable '@CounterID'.Server: Msg 137, Level 15, State 1, Procedure RQCurrencies, Line 36Must declare the variable '@RQCurrencyVal'.Server: Msg 137, Level 15, State 1, Procedure RQCurrencies, Line 37Must declare the variable '@RQCurrencyID'. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-13 : 01:12:06
|
your procedure doesnt make much sense to me. Can you explain what you're requirement is before i tweak code for you?Also just keep in mind that if initial select statements return more than 1 record, you cant store all values in variable. it just holds a single value and all others will be lost. |
|
|
gregdillon
Starting Member
2 Posts |
Posted - 2008-12-15 : 09:43:34
|
quote: Originally posted by visakh16 your procedure doesnt make much sense to me. Can you explain what you're requirement is before i tweak code for you?Also just keep in mind that if initial select statements return more than 1 record, you cant store all values in variable. it just holds a single value and all others will be lost.
Hi, I have updated the code(see below) but am still getting an error for line 4: Incorrect syntax near '@RQCurrency'Basically i need 4 bits of information to be entered into tblRQRates and 1 piece into tblUnitmatrix. This occurs when an insert form is filled and entered. CREATE PROCEDURE [dbo].[RQCurrencies](@RQCurrency char OUTPUT@RQCurrencyVal float OUTPUT@RQCurrencyID INT OUTPUT @CounterID INT OUTPUT)ASDECLARE @EuroVal FloatDECLARE @SterlingVal FloatDECLARE @DollarVal FloatDECLARE @CounterID intDECLARE @RQCurrencyVal FloatDECLARE @RQCurrencyID INTSELECT @CounterID = CounterValue from tblcounterSELECT @RQCurrencyID = CounterValue from tblcounterSELECT @RQCurrencyVal = CurrencyVal from tblCurrencyIESELECT @RQCurrency = Currency from tblCurrencyIESELECT @EuroVal=CurrenyVal from tblCurrencyIE Where Currency = 'Euro'SELECT @SterlingVal=CurrenyVal from tblCurrencyIE Where Currency = 'Sterling'SELECT @DollarVal=CurrenyVal from tblCurrencyIE Where Currency = 'Dollar'UPDATE TBLCOUNTERSET CounterValue=CounterValue+1WHERE COUNTERID=1UPDATE TBLRQRatesSET RQCurrency = 'Euro', RQCurrencyVal = @EuroVal, RQCurrencyID = CounteriDUPDATE TBLRQRatesSET RQCurrency = 'Sterling' , RQCurrencyVal = @SterlingVal, RQCurrencyID = CounteriDUPDATE TBLRQRatesSET RQCurrency = 'Dollar' , RQCurrencyVal = @DollarVal, RQCurrencyID = CounteriDRETURN @CounterIDRETURN @RQCurrencyRETURN @RQCurrencyValRETURN @RQCurrencyIDGO |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-15 : 13:29:05
|
quote: Originally posted by gregdillon
quote: Originally posted by visakh16 your procedure doesnt make much sense to me. Can you explain what you're requirement is before i tweak code for you?Also just keep in mind that if initial select statements return more than 1 record, you cant store all values in variable. it just holds a single value and all others will be lost.
Hi, I have updated the code(see below) but am still getting an error for line 4: Incorrect syntax near '@RQCurrency'Basically i need 4 bits of information to be entered into tblRQRates and 1 piece into tblUnitmatrix. This occurs when an insert form is filled and entered. CREATE PROCEDURE [dbo].[RQCurrencies](@RQCurrency char OUTPUT,@RQCurrencyVal float OUTPUT,@RQCurrencyID INT OUTPUT ,@CounterID INT OUTPUT)ASDECLARE @EuroVal FloatDECLARE @SterlingVal FloatDECLARE @DollarVal FloatDECLARE @CounterID intDECLARE @RQCurrencyVal FloatDECLARE @RQCurrencyID INTSELECT @CounterID = CounterValue from tblcounterSELECT @RQCurrencyID = CounterValue from tblcounterSELECT @RQCurrencyVal = CurrencyVal from tblCurrencyIESELECT @RQCurrency = Currency from tblCurrencyIESELECT @EuroVal=CurrenyVal from tblCurrencyIE Where Currency = 'Euro'SELECT @SterlingVal=CurrenyVal from tblCurrencyIE Where Currency = 'Sterling'SELECT @DollarVal=CurrenyVal from tblCurrencyIE Where Currency = 'Dollar'UPDATE TBLCOUNTERSET CounterValue=CounterValue+1WHERE COUNTERID=1UPDATE TBLRQRatesSET RQCurrency = 'Euro', RQCurrencyVal = @EuroVal, RQCurrencyID = CounteriDUPDATE TBLRQRatesSET RQCurrency = 'Sterling' , RQCurrencyVal = @SterlingVal, RQCurrencyID = CounteriDUPDATE TBLRQRatesSET RQCurrency = 'Dollar' , RQCurrencyVal = @DollarVal, RQCurrencyID = CounteriDRETURN @CounterIDRETURN @RQCurrencyRETURN @RQCurrencyValRETURN @RQCurrencyIDGO
you've missed commasalso did you check if any of select queries which assign value to variables return more than 1 record? |
|
|
|
|
|
|
|