Avatar of lulu50
lulu50
Flag for United States of America asked on

store procedure

Hi,

It's been a long time since I have worked with a store procedure

I created a store procedure I need to exc this store procedure for debugging.

what am i doing wrong?

Exc [obi.dbo.OBI_GrpKeyLOB_Change_Hist_Pro] 3,'7/1/2011','7/1/2011'


If I highlight "Exc [obi.dbo.OBI_GrpKeyLOB_Change_Hist_Pro]  3,'7/1/2011','7/1/2011' " 
 
I get an error that says
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '3'.
 
Exc [obi.dbo.OBI_GrpKeyLOB_Change_Hist_Pro]  3,'7/1/2011','7/1/2011'
should I do this
Exc [obi.dbo.OBI_GrpKeyLOB_Change_Hist_Pro]  (3,'7/1/2011','7/1/2011' )
I am not sure how to run it.


How can I say if the date is not available just don't query it?


GO
/****** Object:  StoredProcedure [dbo].[OBI_GrpKeyLOB_Change_Hist_Pro]    Script Date: 08/08/2011 08:08:03 ******/

/* Exc [obi.dbo.OBI_GrpKeyLOB_Change_Hist_Pro] 3,'7/1/2011','7/1/2011'  */

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[OBI_GrpKeyLOB_Change_Hist_Pro]
   @groupsuffix varchar(8),
   @GetFromDate datetime,  
   @GetToDate datetime  
AS
                     
IF (@GetFromDate <>'') and (@GetToDate <>'')
BEGIN
            SELECT distinct(groupsuffix) ,STUFF((SELECT distinct', ' + t2.ServiceKey
            FROM dbo.OBI_GrpKeyLOB_Change_Hist t2
            WHERE t1.groupsuffix=t2.groupsuffix and t1.Created_Date=t2.Created_Date
            ORDER BY 1
            FOR XML PATH(''), TYPE).value('.','varchar(max)') ,1,2, '') AS Contacinated,
            Status_Flag, created_date
            FROM dbo.OBI_GrpKeyLOB_Change_Hist t1
            
            where ([groupsuffix] LIKE '@groupsuffix%') and Status_Flag = 'C'
             and (Created_Date >= Cast(@GetFromDate as datetime) and
          Created_Date <= Cast(@GetToDate as datetime))
       
 END
 
 ELSE
 BEGIN
               SELECT distinct(groupsuffix) ,STUFF((SELECT distinct', ' + t2.ServiceKey
            FROM dbo.OBI_GrpKeyLOB_Change_Hist t2
            WHERE t1.groupsuffix=t2.groupsuffix and t1.Created_Date=t2.Created_Date
            ORDER BY 1
            FOR XML PATH(''), TYPE).value('.','varchar(max)') ,1,2, '') AS Contacinated,
            Status_Flag, created_date
            FROM dbo.OBI_GrpKeyLOB_Change_Hist t1            
            where ([groupsuffix] LIKE '@groupsuffix%') and Status_Flag = 'C'
  END      
Microsoft SQL ServerMicrosoft SQL Server 2008SQL

Avatar of undefined
Last Comment
lulu50

8/22/2022 - Mon
lludden

Since the first variable is a varchar, you need to pass it a varchar

EXEC [obi.dbo.OBI_GrpKeyLOB_Change_Hist_Pro] '3','7/1/2011','7/1/2011'
lulu50

ASKER
lludden

thank you for helping me

it still says this:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '3'.

Exc [obi.dbo.OBI_GrpKeyLOB_Change_Hist_Pro] '3','7/1/2011','7/1/2011'
ASKER CERTIFIED SOLUTION
tigin44

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
lulu50

ASKER
yes, it was the problem with exec

the next part of my question is how to say if the date does not exist just don't query it?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
lulu50

ASKER
     in the store procedure below if I put like @groupsuffix I don't get any records but if
     I do this LIKE '3%')
I get a lots of records.

what I am doing wrong?


               declare @groupsuffix as varchar(8)
      set  @groupsuffix = '3'              


            SELECT distinct(groupsuffix) ,STUFF((SELECT distinct', ' + t2.ServiceKey
            FROM dbo.OBI_GrpKeyLOB_Change_Hist t2
            WHERE t1.groupsuffix=t2.groupsuffix and t1.Created_Date=t2.Created_Date
            ORDER BY 1
            FOR XML PATH(''), TYPE).value('.','varchar(max)') ,1,2, '') AS Contacinated,
            Status_Flag, created_date
            FROM dbo.OBI_GrpKeyLOB_Change_Hist t1
            
            where ([groupsuffix] LIKE '@groupsuffix%') and Status_Flag = 'C'
lulu50

ASKER
Thanks