Friday, March 9, 2012

DROP DATABASE <@variable>

Hi,
I am getting an error for a very simple SQL statement below. I cannot figure
out why it fails. Is specifying a variable for the Drop Database command not
supported?
DECLARE @.mydb varchar(255)
set @.mydb = 'mytestdb'
DROP DATABASE @.mydbYou have to put it in dynamic sql:
DECLARE @.mydb varchar(255)
set @.mydb = 'mytestdb'
EXEC('DROP DATABASE ' + @.mydb)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Kevin" <nospam@.discussion.com> schrieb im Newsbeitrag
news:OT1ssOxWFHA.3676@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I am getting an error for a very simple SQL statement below. I cannot
> figure out why it fails. Is specifying a variable for the Drop Database
> command not supported?
> DECLARE @.mydb varchar(255)
> set @.mydb = 'mytestdb'
> DROP DATABASE @.mydb
>
>|||Hi
Variables are not supported.
Build a string up and use EXEC
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Kevin" <nospam@.discussion.com> wrote in message
news:OT1ssOxWFHA.3676@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I am getting an error for a very simple SQL statement below. I cannot
> figure out why it fails. Is specifying a variable for the Drop Database
> command not supported?
> DECLARE @.mydb varchar(255)
> set @.mydb = 'mytestdb'
> DROP DATABASE @.mydb
>
>|||Your sample statement worked. Thank you!
"Jens S $B!& (Bmeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wro
te in
message news:%23LKU$UxWFHA.2540@.tk2msftngp13.phx.gbl...
> You have to put it in dynamic sql:
> DECLARE @.mydb varchar(255)
> set @.mydb = 'mytestdb'
> EXEC('DROP DATABASE ' + @.mydb)
>
> --
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "Kevin" <nospam@.discussion.com> schrieb im Newsbeitrag
> news:OT1ssOxWFHA.3676@.TK2MSFTNGP10.phx.gbl...
>|||Now the statement worked. Thank you.
"Mike Epprecht (SQL MVP)" <mike@.epprecht.net> wrote in message
news:%23tnFKWxWFHA.2256@.TK2MSFTNGP14.phx.gbl...
> Hi
> Variables are not supported.
> Build a string up and use EXEC
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> "Kevin" <nospam@.discussion.com> wrote in message
> news:OT1ssOxWFHA.3676@.TK2MSFTNGP10.phx.gbl...
>

No comments:

Post a Comment