|
|||||||
| Programming, Coding, (Web)Design Discuss all your programming or design needs with likeminded people. |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
I can fart in 7 languages
|
SQL stored procedure
This is driving me up the freaking wall
![]() I'm trying to make a stored procedure that checks to see if the values entered already exist. However, it keeps telling me: Incorrect syntax near the keyword 'if'. Utilising the auto syntax checker I find: "Must declare the scalar variable" on each of the variables. Code:
create procedure sp_import(@desc as nvarchar(max), @amount as nvarchar(50), @type as nvarchar(50), @accid as int, @business as int, @proc as int)
if not exists(select * from Transactions where Description = @desc and Amount = @amount and Type = @type and accountid = @accid and Business = @business and Processed = @proc)
begin
insert into Transactions (description,amount,type,AccountID,business,processed) values (@desc,@amount,@type,@accid,@business,@proc)
end
__________________
![]() I don't get paid to know the answer, therefore I'm far more likely to give you a straight and honest answer. Mods Rig, Box Mods Rig, Folding details |
|
|
|
|
|
|
|
I can fart in 7 languages
|
Re: SQL stored procedure
Code:
CREATE procedure [dbo].[sp_ImportTrans] @Date as Date, @Description as nvarchar(MAX), @Amount as nvarchar(50), @Type as nvarchar(50), @Account as nvarchar(50), @Business as bit, @Processed as bit as if (select count(*) from transactions where date = @Date and amount = @Amount and description = @Description and type = @Type and accountid = (select id from account where name = @Account) and business = @Business and processed = @Processed ) = 0 insert into transactions (date,description,amount,type,accountid,business,processed) values( @Date, @Description, @Amount, @Type, (select id from account where name = @Account), @Business, @Processed ) else insert into Tran_Dupes (date,description,amount,type,account) values( @Date, @Description, @Amount, @Type, (select id from account where name = @Account) ) It imported nearly 500 transactions into a (an?) SQL database in about 1 second.
__________________
![]() I don't get paid to know the answer, therefore I'm far more likely to give you a straight and honest answer. Mods Rig, Box Mods Rig, Folding details Last edited by Takaharu; Dec 17, 2010 at 09:12 PM. |
|
|
|
![]() |
| Thread Tools | |
|
|