SQL COMMAND

Hi All,

I usually write command :

USE DBF
Press F5

The current database immediately change to DBF Name above.

I try to use :

EXEC('USE ' + @strDBClient)

It does not as expected.

What's wrong ?

Thank you.
LVL 1
emi_sastraAsked:
Who is Participating?
 
CodeCruiserCommented:
Try

SET @SCRIPT = 'DELETE FROM ' + @strLedgerFileName  

EXEC('USE ' + @strDBClient + '; ' + @SCRIPT)
0
 
CodeCruiserCommented:
You need to execute rest of the code in the same batch and it will execute under that database.
0
 
emi_sastraAuthor Commented:
I try below :

EXEC('USE ' + @strDBClient)

SET @SCRIPT = 'DELETE FROM ' + @strLedgerFileName  
 EXEC(@SCRIPT)

Get message table not found ?

Thank you.
0
 
emi_sastraAuthor Commented:
Yes, it works.

Thank you very much for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.