Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 715261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:10:02+00:00 2026-05-14T05:10:02+00:00

ALTER PROCEDURE [dbo].[GetDocumentsAdvancedSearch] @SDI CHAR(10) = NULL ,@Client CHAR(4) = NULL ,@AccountNumber VARCHAR(20) =

  • 0
 ALTER PROCEDURE [dbo].[GetDocumentsAdvancedSearch]
          @SDI  CHAR(10) = NULL
             ,@Client CHAR(4) = NULL
             ,@AccountNumber VARCHAR(20) = NULL
         ,@Address VARCHAR(300)  = NULL
         ,@StartDate DATETIME = NULL
         ,@EndDate DATETIME = NULL
         ,@ReferenceID CHAR(14) = NULL
    AS
    BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

      -- DECLARE
      DECLARE @Sql        NVARCHAR(4000)
      DECLARE @ParamList  NVARCHAR(4000)

      SELECT  @Sql = 'SELECT 
                        DISTINCT ISNULL(Documents.DocumentID, '') 
                       ,Person.Name1
                       ,Person.Name2
                       ,Person.Street1
                       ,Person.Street2
                       ,Person.CityStateZip
                       ,ISNULL(Person.ReferenceID,'')
                       ,ISNULL(Person.AccountNumber,'')
                       ,ISNULL(Person.HasSetPreferences,0)
                       ,Documents.Job
               ,Documents.SDI
                       ,Documents.Invoice
                       ,ISNULL(Documents.ShippedDate,'')
                       ,ISNULL(Documents.DocumentPages,'')
                       ,Documents.DocumentType
                       ,Documents.Description
                       FROM
                       Person
                       LEFT OUTER JOIN Documents ON Person.PersonID = Documents.PersonID
                       LEFT OUTER JOIN DocumentType ON Documents.DocumentType = DocumentType.DocumentType
                       LEFT OUTER JOIN Addressess   ON Person.PersonID = Addressess.PersonID'

       SELECT @Sql = @Sql + ' WHERE 
                       Documents.SDI IN ( '+ QUOTENAME(@sdi) + ') OR (Person.AssociationID = ' + ''' 000000 + ''' + 'AND Person.Client = ' + QUOTENAME(@Client)

        IF NOT (@AccountNumber IS  NULL)
        SELECT @Sql = @Sql + 'AND Person.AccountNumber LIKE' + QUOTENAME(@AccountNumber)
        IF NOT (@Address IS  NULL)
        SELECT @Sql = @Sql + 'AND Person.Name1 LIKE' +QUOTENAME(@Address)+ 'AND Person.Name2 LIKE' +QUOTENAME(@Address)+ 'AND Person.Street1 LIKE' +QUOTENAME(@Address)+ 'AND Person.Street2 LIKE' +QUOTENAME(@Address)+ 'AND Person.CityStateZip LIKE' +QUOTENAME(@Address)
        IF NOT (@StartDate IS  NULL)
        SELECT @Sql = @Sql + 'AND Documents.ShippedDate >=' +@StartDate
        IF NOT (@EndDate IS NULL)
        SELECT @Sql = @Sql + 'AND Documents.ShippedDate <=' +@EndDate
        IF NOT (@ReferenceID IS  NULL)
        SELECT @Sql = @Sql + 'AND Documents.ReferenceID =' +QUOTENAME(@ReferenceID)

        -- Insert statements for procedure here
       -- PRINT @Sql
        SELECT @ParamList = '@Psdi CHAR(10),@PClient CHAR(4),@PAccountNumber VARCHAR(20),@PAddress VARCHAR(300),@PStartDate DATETIME ,@PEndDate DATETIME,@PReferenceID CHAR(14)'  
        EXEC SP_EXECUTESQL @Sql,@ParamList,@Sdi,@Client,@AccountNumber,@Address,@StartDate,@EndDate,@ReferenceID
        --PRINT @Sql


    END

ERROR

Msg 102, Level 15, State 1, Line 23
Incorrect syntax near ‘000000’. Msg
105, Level 15, State 1, Line 23
Unclosed quotation mark after the
character string ‘AND Person.Client =
[1 ]AND Person.AccountNumber
LIKE[1]’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:10:02+00:00Added an answer on May 14, 2026 at 5:10 am

    Check out these lines of your statement:

    'AND Person.AccountNumber LIKE' + QUOTENAME(@AccountNumber)
    'AND Person.Name1 LIKE' +QUOTENAME(@Address)+ 'AND Person.Name2 LIKE' +QUOTENAME(@Address)+ 'AND Person.Street1 LIKE' +QUOTENAME(@Address)+ 'AND Person.Street2 LIKE' +QUOTENAME(@Address)+ 'AND Person.CityStateZip LIKE' +QUOTENAME(@Address)
    

    This will result in something like

    AND Person.AccountNumber LIKE[13123]AND Person.Name1 LIKE[bla]AND Person.Name2 LIKE[alskda] 
    

    and so forth – you need to start adding some spacing!

    • put a space between your LIKE keyword and the value it’s referring to:

       AND Person.AccountNumber LIKE ''' + @AccountNumber + '''' +
      
    • put a space before every AND in your statements

       SELECT @Sql = @Sql + ' AND Person.Name1 LIKE ''' + @Address + 
                     ''' AND Person.Name2 LIKE ''' + @Address + 
                     ''' AND Person.Street1 LIKE ''' + @Address + 
                     ''' AND Person.Street2 LIKE '  ........
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following stored procedure. ALTER PROCEDURE [dbo].[spList_Report] @id INT, @startDate DATETIME =
The code is as follows: ALTER PROCEDURE dbo.pdpd_DynamicCall @SQLString varchar(4096) = null AS Begin
ALTER PROCEDURE [dbo].[STL_ADDNEWROLE](@ROLENAME VARCHAR(100), @STATUS BIT) AS BEGIN SET NOCOUNT ON; IF(@ROLENAME IS NULL
I have a SP ALTER PROCEDURE dbo.sp_Compare @lst varchar(100), @frst varchar(100) = NULL, @passportNo
ALTER PROCEDURE [dbo].[AmendInsertDuplicateFields] (@ReportID varchar(50)) AS BEGIN DECLARE @NewReportID VARCHAR(50) SET @NewReportID = NEWID()
ALTER PROCEDURE [dbo].[GetTimeSheetsAttendance] @WhereClause varchar AS EXEC ('Select vwEmployeeList.ID,vwEmployeeList.Code, tbGNClient.FName + '' '' +
Hi I have a Stored Procedure ALTER PROCEDURE [dbo].[usp_EP_GetTherapeuticalALternates] ( @NDCNumber CHAR(11) , @patientid
I have this stored Proc: ALTER Procedure [dbo].[GetWebinars] ( @GroupingCode varchar(max) = 'AVM', @ItemNumber
I have the following SQL: ALTER PROCEDURE [dbo].[SP_Products_GetList] @CatID int, @CatName int, @SortBy varchar(50),
--Stored procedure ALTER PROCEDURE [dbo].[Test] @USERID varchar(25) AS BEGIN SET NOCOUNT ON IF NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.