Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
ALTER proc [dbo].[InsertUserIdMap]
@userid varchar(50),
@type varchar(50),
@typeid varchar(50),
@exists int=1 output
as
begin
declare @match varchar(500)
set @match =(select User_ID from UserIDMapping where User_ID =@userid and TypeId=@typeid)
 
if(@type='ADMIN')
begin
if exists  (@match)
select @exists
else
insert into UserIDMapping (User_ID ,Table_Ref ,TypeId ) values (@userid ,'adminb2b' ,@typeid )
set @exists=0
end
end




there is an error Incorrect syntax @match
Posted
Updated 15-Mar-12 0:52am
v2

the error is here,insert begin and end condition
use the below solution


SQL
ALTER proc [dbo].[InsertUserIdMap]
@userid varchar(50),
@type varchar(50),
@typeid varchar(50),
@exists int=1 output
as
begin
declare @match varchar(500)
set @match =(select User_ID from UserIDMapping where User_ID =@userid and TypeId=@typeid)
 
if(@type='ADMIN')
begin
if exists  (@match)
BEGIN
select @exists
END
else
BEGIN
insert into UserIDMapping (User_ID ,Table_Ref ,TypeId ) values (@userid ,'adminb2b' ,@typeid )
set @exists=0
END
end
end



it is good if u insert begin and end in every starting and closing condition
 
Share this answer
 
v2
Hi,
try This hope it will Help

ALTER proc [dbo].[InsertUserIdMap]
@userid varchar(50),
@type varchar(50),
@typeid varchar(50),
@exists int=1 output
as
begin
declare @match varchar(500)
select @match=User_ID from UserIDMapping where User_ID =@userid and TypeId=@typeid)
SQL
if(@type='ADMIN')
begin
if exists  (@match)
BEGIN
select @exists
END
else
BEGIN
insert into UserIDMapping (User_ID ,Table_Ref ,TypeId ) values (@userid ,'adminb2b' ,@typeid )
set @exists=0
END
end


end

best luck
 
Share this answer
 
v2
See this:

SQL
ALTER proc [dbo].[InsertUserIdMap]
    @userid varchar(50),
    @type varchar(50),
    @typeid varchar(50),
    @exists int=1 output
as
begin
if(@type='ADMIN')
    begin
    if exists(select User_ID from UserIDMapping where User_ID =@userid and TypeId=@typeid)
        begin
        set @exists=1
        end
    else
        begin
        insert into UserIDMapping (User_ID ,Table_Ref ,TypeId ) values (@userid ,'adminb2b' ,@typeid )
        set @exists=0
        end
    end
end
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900