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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:14:21+00:00 2026-05-30T08:14:21+00:00

Here is the following piece of code that I am trying to execute on

  • 0

Here is the following piece of code that I am trying to execute on SQL Server.

DECLARE @string NVARCHAR(MAX) = '
    CREATE PROC [dbo].[Trend]
    @slsID NVARCHAR(20)
    AS
    BEGIN
    SET NOCOUNT ON
    DECLARE @BeginningRange varchar(20),
    @EndingRange varchar(20)
    SET @EndingRange = ''12*13''
    SET @BeginningRange = ''12*02''
    ;WITH CTE1 AS(
             SELECT 
             dbo.Field1,dbo.Field2,dbo.Field3
             FROM dbo.Table1 join dbo.Table2 where...conditions
             weekNum BETWEEN (@BeginningRange) AND (@EndingRange)
                 )
    SELECT * FROM CTE1 
    UNPIVOT
      ( numbers for type in (Field1, Field2, Field3, Field4)
      ) as p PIVOT
      (
      Sum(numbers) for
      WeekNum in ([12*02],[12*03],[12*04],[12*05],[12*06],[12*07],[12*08],[12*09],[12*10],                                                         [12*11],[12*12],[12*13])
      ) as q
      END
'
    EXECUTE SP_EXECUTESQL @STRING

When I try to run this, it errors out saying that

“Incorrect syntax near the keywor ‘as'”

I took this code out and executed it separately and it didn’t error out. Am I missing something here?

  • 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-30T08:14:23+00:00Added an answer on May 30, 2026 at 8:14 am

    Look like missing parentheses around the parameter to the procedure.

    One trick you can use is the print out the sql statement and then try to run that – the error message might give you more info

    print @STRING
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code here that won't run on ARC since it combines
I have the following piece of code that I am wondering if it can
I have been trying to find ways to make the following piece of code
This following piece of code is meant to create a multilevel array, print it,
I've got a piece of code that returns a super-long string that represents search
I found the following piece of JavaScript code (maybe here at Stack Overflow?) for
Following is a piece of jquery code that is driving me nuts var count
here the following code is used to view the present modal view controller. [[self
Have a look here: In the following code, what would be the type of
I am trying to reach the following result here I know how to configure

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.