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 986883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:23:22+00:00 2026-05-16T05:23:22+00:00

The following script I have tried to run in MS server management studio and

  • 0

The following script I have tried to run in MS server management studio and this is work perfectly fine.

SELECT ucb.UserFirstName, ucb.UserLastName, ucb.userid, c.caseid
FROM Cases c 
    LEFT JOIN Users ucb ON (c.ConfirmedBy=ucb.UserID) 
    JOIN RealtorStaff rs ON c.realtorstaffid=rs.realtorstaffid 
WHERE c.ConfirmedBy is not null AND c.CaseStatusID <> 7 
    AND (
            SELECT COUNT(ServiceID) 
            FROM Cases ca JOIN Services s ON ca.CaseID=s.CaseID 
            WHERE ca.CaseID=c.CaseID 
                AND s.ServiceTypeID != 8 
                AND s.ServiceTypeID != 9 
                AND s.ServiceTypeID != 10 
                AND s.ServiceTypeID != 14 
                AND s.ServiceTypeID != 15 
                AND s.ServiceStatusID != 7)>0 
    AND c.DateConfirmed >= '2010-08-06 00:00:00' 
    AND c.DateConfirmed <= '2010-08-06 23:59:59' 
ORDER BY ucb.UserFirstName, ucb.UserLastName, c.caseid

Somehow after I tried to convert it into the following scrip so that I can run it under sp_executesql and error message display (Msg 102, Level 15, State 1, Line 11
Incorrect syntax near ‘8’).

--  /* for testing purpose
    Declare @startdate DATETIME; set @startdate = '2010-08-06'
    Declare @enddate DATETIME; set @enddate = '2010-08-06'
--  */

    Declare @actualstartdate varchar(20); set @actualstartdate = replace(convert(char(26),@startdate,102),'.','-')+' 00:00:00'
    Declare @actualenddate varchar(20); set @actualenddate = replace(convert(char(26),@enddate,102),'.','-')+' 23:59:58'

    DECLARE @SQL nvarchar(500)

    SET @SQL = 'SELECT ucb.UserFirstName, ucb.UserLastName, ucb.userid, c.caseid
                 INTO ##actual_assigned_cases
                 FROM Cases c 
                    LEFT JOIN Users ucb ON (c.ConfirmedBy=ucb.UserID) 
                    JOIN RealtorStaff rs ON c.realtorstaffid=rs.realtorstaffid 
                 WHERE c.ConfirmedBy is not null '

    SET @SQL = @SQL+' AND c.CaseStatusID <> 7 
                AND (SELECT COUNT(ServiceID) 
                FROM Cases ca 
                    JOIN Services s ON ca.CaseID=s.CaseID 
                WHERE ca.CaseID=c.CaseID 
                AND s.ServiceTypeID != 8
                AND s.ServiceTypeID != 9
                AND s.ServiceTypeID != 10 
                AND s.ServiceTypeID != 14
                AND s.ServiceTypeID != 15 
                AND s.ServiceStatusID != 7) > 0'


    SET @SQL = @SQL+' AND c.DateConfirmed >= '''+@actualstartdate+''' 
                AND c.DateConfirmed <= '''+@actualenddate+'''
                ORDER BY ucb.UserFirstName, ucb.UserLastName, c.caseid'

    EXECUTE sp_executesql @SQL

Does anyone know what is going on here? and how can I fix this issue??

  • 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-16T05:23:23+00:00Added an answer on May 16, 2026 at 5:23 am

    You have more than 500 chars, so @SQL got truncated.
    change to:

      DECLARE @SQL nvarchar(4000)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script select c.id from .TBL_COUPONS. as c inner join .TBL_BUSINESS.
I have a script that will run on server daily to download data from
I have run the following code in this page RsyntaxTextArea using Java and i
I have a page on the server and i tried to run it like
I have following script that executes all the .reg files in the current directory.
Currently Im have the following script which checks to see if a checkbox value
Hi I have the following script in my form function pdf() { var frm
I have the following script below where I try to mimic a file upload
I have the following script: (function($) { $.fn.easyPaginate = function(options){ var defaults = {
I have the following script running successfully. However if I try to use a

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.