Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Posts
    7

    Question Unanswered: DatabaseName Problem

    DECLARE @DatabaseName varchar(10)
    DECLARE @OwnerName varchar(10)
    DECLARE @TableName varchar(10)

    SET @DatabaseName='TempDatabase'
    SET @OwnerName='XYZ'
    SET @TableName='TempTable'

    select * from @DatabaseName.@OwnerName.@TableName

    this is not working.

    SEND ME HELP AS SOON AS POSSIBLE

  2. #2
    Join Date
    Jan 2003
    Location
    India
    Posts
    523
    Quote Originally Posted by akshit
    DECLARE @DatabaseName varchar(10)
    DECLARE @OwnerName varchar(10)
    DECLARE @TableName varchar(10)

    SET @DatabaseName='TempDatabase'
    SET @OwnerName='XYZ'
    SET @TableName='TempTable'

    select * from @DatabaseName.@OwnerName.@TableName

    this is not working.

    SEND ME HELP AS SOON AS POSSIBLE
    you will have to use dynamic sql something like this:

    DECLARE @DatabaseName varchar(10)
    DECLARE @OwnerName varchar(10)
    DECLARE @TableName varchar(10)
    declare @sql nvarchar(1000)
    SET @DatabaseName='databasename'
    SET @OwnerName='dbo'
    SET @TableName='tablename'

    set @sql='select * from '+@DatabaseName+'.'+@OwnerName+'.'+@TableName

    exec @sql

  3. #3
    Join Date
    Nov 2003
    Posts
    94
    It would also help to not assign 12 characters to a 10 character varchar().

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    ...but who's counting...
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •