Click here to Skip to main content
15,899,313 members
Home / Discussions / Database
   

Database

 
AnswerRe: What am I missing here? - (Table Variable) Pin
Blue_Boy12-Oct-10 22:11
Blue_Boy12-Oct-10 22:11 
GeneralRe: What am I missing here? - (Table Variable) Pin
Andy_L_J12-Oct-10 22:37
Andy_L_J12-Oct-10 22:37 
GeneralRe: What am I missing here? - (Table Variable) Pin
Blue_Boy12-Oct-10 22:41
Blue_Boy12-Oct-10 22:41 
GeneralRe: What am I missing here? - (Table Variable) Pin
Andy_L_J12-Oct-10 23:23
Andy_L_J12-Oct-10 23:23 
GeneralRe: What am I missing here? - (Table Variable) Pin
Mycroft Holmes13-Oct-10 0:58
professionalMycroft Holmes13-Oct-10 0:58 
AnswerRe: What am I missing here? - (Table Variable) Pin
Corporal Agarn13-Oct-10 9:44
professionalCorporal Agarn13-Oct-10 9:44 
GeneralRe: What am I missing here? - (Table Variable) Pin
Andy_L_J13-Oct-10 9:48
Andy_L_J13-Oct-10 9:48 
AnswerRe: What am I missing here? - (Table Variable) Pin
www.Developerof.NET17-Oct-10 9:17
www.Developerof.NET17-Oct-10 9:17 
This one does execute.
DECLARE @SomeLongName VarChar(100) = 'Some long text'    
               
    DECLARE @Sql VarChar(1000) 
    SET @Sql='DECLARE @temp TABLE( someCode VarChar(10) )' 
	SET @Sql=@Sql+
            'INSERT @temp SELECT MAX(SomeCode) ' +
            'FROM MyTable ' +
            'WHERE [Name] LIKE''' + LEFT(REPLACE( @SomeLongName, ' ', ''), 3) + '%'''
               
    EXEC (@Sql)



The problem here is the scope in which the sql statement executes. The @temp table variable declared is different from the @temp variable used in the inline query as the scope of both the queries are different. To make the query work we need to run the query in same scope ie declare the table variable using the same SQL satements as one used for the query.
When you fail to plan, you are planning to fail.

Questionsql novice: how to find only duplicates Pin
PJ Arends12-Oct-10 18:55
professionalPJ Arends12-Oct-10 18:55 
AnswerRe: sql novice: how to find only duplicates Pin
Blue_Boy12-Oct-10 20:35
Blue_Boy12-Oct-10 20:35 
GeneralRe: sql novice: how to find only duplicates Pin
PJ Arends13-Oct-10 6:07
professionalPJ Arends13-Oct-10 6:07 
AnswerRe: sql novice: how to find only duplicates Pin
J4amieC12-Oct-10 21:59
J4amieC12-Oct-10 21:59 
GeneralRe: sql novice: how to find only duplicates Pin
PJ Arends13-Oct-10 6:08
professionalPJ Arends13-Oct-10 6:08 
AnswerRe: sql novice: how to find only duplicates Pin
Mycroft Holmes13-Oct-10 1:01
professionalMycroft Holmes13-Oct-10 1:01 
GeneralRe: sql novice: how to find only duplicates Pin
PJ Arends13-Oct-10 6:11
professionalPJ Arends13-Oct-10 6:11 
Questionmodify a table scheme [modified] Pin
genieabdo12-Oct-10 1:15
genieabdo12-Oct-10 1:15 
AnswerRe: modify a table scheme Pin
Blue_Boy12-Oct-10 2:11
Blue_Boy12-Oct-10 2:11 
GeneralRe: modify a table scheme Pin
genieabdo12-Oct-10 2:25
genieabdo12-Oct-10 2:25 
AnswerRe: modify a table scheme Pin
Gerben Jongerius12-Oct-10 3:13
Gerben Jongerius12-Oct-10 3:13 
AnswerRe: modify a table scheme Pin
genieabdo12-Oct-10 4:26
genieabdo12-Oct-10 4:26 
AnswerRe: modify a table scheme Pin
Bernhard Hiller12-Oct-10 20:58
Bernhard Hiller12-Oct-10 20:58 
QuestionNumber of query srtings and destination values are not matched" Pin
Thanusree Duth11-Oct-10 21:25
Thanusree Duth11-Oct-10 21:25 
AnswerRe: Number of query srtings and destination values are not matched" Pin
Goutam Patra11-Oct-10 21:58
professionalGoutam Patra11-Oct-10 21:58 
QuestionPrint numbers Pin
SatyaKeerthi1511-Oct-10 21:12
SatyaKeerthi1511-Oct-10 21:12 
AnswerRe: Print numbers Pin
Blue_Boy11-Oct-10 21:43
Blue_Boy11-Oct-10 21:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.