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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:36:56+00:00 2026-05-26T18:36:56+00:00

I have a question here.I better paste my code first SET @Sql = ‘DECLARE

  • 0

I have a question here.I better paste my code first

SET @Sql = 'DECLARE @Date_From VARCHAR(10);
            DECLARE @Date_To VARCHAR(10);
            DECLARE @TempTable VARCHAR(500);
            SET @TempTable = #'+@TblName+'; 
            SET @Date_From = '''+CONVERT(VARCHAR(10),DATEADD(d,DATEDIFF(d,0,GETDATE()),0)-@DayPrior,120)+''';
            SET @Date_To = '''+CONVERT(VARCHAR(10),DATEADD(d,DATEDIFF(d,0,GETDATE()),0)-@DayPrior,120)+''';
            '+ @Sql

I try to print out @Sql using PRINT
and i get this result

DECLARE @Date_From VARCHAR(10);
DECLARE @Date_To VARCHAR(10);
DECLARE @TempTable VARCHAR(500);
SET @TempTable = #RawData_New; 
SET @Date_From = '2011-04-05';
SET @Date_To = '2011-04-05';

Select Distinct Coloum1,Coloum2 into @TempTable 
from RawData_New with(nolock)  
here Convert(varchar(10), Date_Tm, 120) Between @Date_From And @Date_To

I get an error after executing this sql,i get an error:

Incorrect syntax near '@TempTable'.

Is there any Constraint to this # symbol or inside the select Statement around INTO?

I tried that not variable assigment on @TempTable that i directly put the @TempTable Value inside the sql like

Select Coloum1,Coloum2 into #RawData_New
from RawData_New with(nolock)  
here Convert(varchar(10), Date_Tm, 120) Between @Date_From And @Date_To

Its works fine and i get my expected result? is there any solution to solve this?

Thanks you.

PS: I am quite new to T-Sql, Please dont hesitated to point out my mistake.We all Learn from Mistake.Any Sorry for my poor English Level.

Regards:

LiangCK

  • 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-26T18:36:56+00:00Added an answer on May 26, 2026 at 6:36 pm

    You have a couple of issues:

    • You can’t assign a table name like that. You need to assign the variable to the string representing the table name: SET @TempTable = ''#'+@TblName+'''; The extra quotes will make the table a string

    • You need to make the second query Dynamic SQL as well. Basically parse it with the table name at runtime:

    ..

    'Select Coloum1,Coloum2 into' + @TableName +'
    from SPC.dbo.Lube_RawData_New with(nolock)  
    where Convert(varchar(10), Date_Tm, 120) Between @Date_From And @Date_To'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question here regarding iPhone app submission. I have a free application
C# question here.. I have a UTF-8 string that is being interpreted by a
I have an other active question HERE regarding some hopeless memory issues that possibly
I have a simple unit test case (extensive question here ) on a configuration
The question raised from the question here . In order to have search engines
Actually my question here is: are null and nil equivalent or not? I have
Bit of a beginner question here: Say I have a block of xml: <root>
Just a quick question here. I have a program in which I need to
This is a continuation of the question here: JBoss - does app have to
Pardon the dumb newbie question here; web programming isn't my forte... (blush) I have

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.