Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 336
  • Last Modified:

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.
0
emi_sastra
Asked:
emi_sastra
  • 2
  • 2
1 Solution
 
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
 
CodeCruiserCommented:
Try

SET @SCRIPT = 'DELETE FROM ' + @strLedgerFileName  

EXEC('USE ' + @strDBClient + '; ' + @SCRIPT)
0
 
emi_sastraAuthor Commented:
Yes, it works.

Thank you very much for your help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now