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

  • Home
  • SEARCH
  • 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 8195625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:12:00+00:00 2026-06-07T05:12:00+00:00

i have create Sp that return record on condition. it is work on my

  • 0

i have create Sp that return record on condition. it is work on my local server but when i deploy on another server im getting error

153|error|500|Incorrect syntax near ‘*’. Incorrect syntax near ‘)’.
Incorrect syntax near ‘)’. Unexpected error occured while retrieving
data.Please try again later|

This is my query:-

     DECLARE @MemberID int  
    DECLARE @FolderID INT -- 1 = Inbox, 2 = Draft, 3 = Sent Items, 4 = Deleted Items, 5 = Templates etc    
     DECLARE @Email varchar(50)  
    DECLARE @OrderBy VARCHAR(50)
    DECLARE @PageSize INT  
    DECLARE @PageNumber INT  
    DECLARE @EnvelopeCurrentStatus varchar(5)  
    DECLARE @Subject varchar(50)   
    DECLARE @DateFrom VARCHAR(15)
    DECLARE @DateTo VARCHAR(15) 




    SET @MemberID =35185  
    SET @FolderID =1 -- 1 = Inbox, 2 = Draft, 3 = Sent Items, 4 = Deleted Items, 5 = Templates etc    
    SET @Email ='sd' 
    SET @OrderBy = 'ti.ID DESC'  
    SET @PageSize =10  
    SET @PageNumber =1  
    SET @EnvelopeCurrentStatus  = '' 
    SET @Subject  = ''  
    SET @DateFrom  = '1/1/1990'   
    SET @DateTo  = '1/1/2990'
--,@DocGuid uniqueidentifier='00000000-0000-0000-0000-000000000000 '

    DECLARE @SQL VARCHAR(MAX)  
    DECLARE @SQL1 VARCHAR(MAX)  
    DECLARE @SQL2 VARCHAR(MAX)  
    DECLARE @SQL3 varchar(Max)  
    DECLARE @Select varchar(50)  
    DECLARE @Expr varchar(max)  
    SET @SQL = ''  
    SET @OrderBy = ''  

    SET @Expr = ''  
    IF ((@DateFrom <> '' AND @DateFrom IS NOT NULL) AND (@DateTo <> '' AND @DateTo IS NOT NULL ) )  
           SET @Expr = @Expr + ' AND ti.CreatedOn BETWEEN ''' + @DateFrom + ''' AND ''' + @DateTo+''''

    IF @Subject <> '' AND @Subject IS NOT NULL 
     begin  
      BEGIN TRY
      DECLARE @nPortalUID AS uniqueidentifier
      SET @nPortalUID = CAST(@Subject AS uniqueidentifier)
      SET @Expr = @Expr + ' AND  ti.TemplateID= '''+@Subject+' '''
      end try

      BEGIN catch
      SET @Expr = @Expr + ' and ti.Subject LIKE ''%'+@Subject+'%'' '
      end catch
     end     




    IF @EnvelopeCurrentStatus <> '' AND @EnvelopeCurrentStatus IS NOT NULL  
            SET @Expr = @Expr + ' AND ti.EnvelopeCurrentStatus = ''' + cast( @EnvelopeCurrentStatus AS varchar(5))+ ''''

    IF @OrderBy ='' AND @OrderBy IS NOT NULL   
            SET @OrderBy = 'ti.ID DESC'
    ELSE   
            SET @OrderBy = @OrderBy  

    DECLARE @IsShare BIT
    DECLARE @ParentID INT
    SELECT @IsShare = m.MUIsShare, @ParentID = m.createdby FROM tblcontact m WHERE m.ID = @MemberID

    DECLARE @MemberParentID VARCHAR(MAX)

    IF @IsShare = 1 
    BEGIN
    SET @MemberParentID = cast(@MemberID AS varchar(5))
        --SET @MemberParentID = cast(@MemberID AS varchar(5))+ ', ' + cast(@ParentID AS varchar(5))
    END
    ELSE
    BEGIN
        SET @MemberParentID = cast(@MemberID AS varchar(5))
    END

    SET @SQL1 = 'SELECT * INTO #TMP FROM (  
                    SELECT * FROM (  
                        SELECT (  
                            SELECT Count(*) FROM TemplateInfo ti  WHERE (ti.FolderID = '+ cast( @FolderID AS varchar(5) )+ ') AND (ti.MemberID IN( '+ @MemberParentID + '))  AND (ti.EnvelopeStatus = 2) '  

    SET @SQL2 = ' OR  (ti.ID IN (SELECT TempleteInfoID  FROM  Recipients AS r  WHERE (Email = '''+ @Email+''')  AND (FolderID = '+ cast( @FolderID AS varchar(5))+') ) ) ) AS TotalRecord  
                , ROW_NUMBER() OVER(ORDER BY '+ @OrderBy + ') AS ROWID , ti.ID  , ti.TemplateID  , ti.EnvelopeStatus  , ti.EnvelopeCurrentStatus  , ti.Subject  , ti.CreatedOn AS SentDate  
                , ti.CreatedOn  , ti.ModifiedOn  , m.FirstName + '' '' + m.LastName AS Sender  , m.Email AS SenderEmail  
                FROM TemplateInfo ti  LEFT OUTER JOIN tblcontact AS m ON ti.MemberID = m.ID  
                WHERE (ti.FolderID = '+ cast( @FolderID AS varchar(5))+ ') AND (ti.MemberID IN( '+ @MemberParentID + '))  AND (ti.EnvelopeStatus = 2) '  

    SET @SQL3 = ' OR (ti.ID IN ( SELECT TempleteInfoID   FROM  Recipients AS r  WHERE (Email = '''+ @Email+''')  AND (FolderID = '+ cast( @FolderID AS varchar(5)) + ') ) ) ) AS Template  
                    WHERE ROWID BETWEEN  '+ CAST( (@PageNumber - 1) * @PageSize + 1 AS VARCHAR(5)) +' AND '+CAST (@PageNumber*@PageSize AS  VARCHAR(5)) + ' ) AS TmpTable  

                SELECT * FROM #TMP  

                SELECT r.ID  , r.Guid  , r.Name  , r.Email  , r.RecipientOrder  , r.Status  , r.ModifiedOn  , r.TempleteInfoID  
                , CASE WHEN r.Status = 0 THEN ''Waiting to Sign''  WHEN r.Status = 1 THEN ''Completed''  WHEN r.Status = 2 THEN ''Declined'' END AS StatusText  
                FROM Recipients r WHERE r.IsActive <> 0 and r.TempleteInfoID IN (SELECT ID FROM  #TMP)  

                SELECT * FROM UsedCustomFields ucf WHERE ucf.TemplateInfoID IN (SELECT ID FROM  #TMP)  

                DROP TABLE #TMP '  

    SET @SQL = @SQL1 + @Expr + @SQL2 +@Expr + @SQL3  
    select @SQL
    --PRINT (@SQL)  
    EXEC (@SQL);  

    IF @@Error <> 0
    BEGIN
        RAISERROR('Unexpected error occured while retrieving data.Please try again later',16 , 1)
    END
  • 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-06-07T05:12:03+00:00Added an answer on June 7, 2026 at 5:12 am

    One possibility is the data in production table contains quotes(‘). Since you are using dynamic sql, if the data itself contains a quote, it takes as the termination of the query string and thus query fails

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a project we have a requirement to create an interfacedefinition that will return
I have created a function that will return the string path from my DB.
If i have a controller action Create that returns a view with the following
I have created a custom method that will return unique items, together with the
Lets say I have a recursive function that creates lists within lists. It return
I have a stdClass object created from json_decode that won't return the right number
I have a field on a from that a user creates a return code.
I have to create app that provides online radio streaming (icecast), preferably .ogg format.
I have create a vcf file that contains contacts by using this code ContentResolver
So I have to create a game of craps that takes into account bets

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.