+ Reply to Thread
Results 1 to 2 of 2

Thread: error creating object

  1. #1

    error creating object

    My SQL looks like this:
    Code:
    :SETVAR VAR_DB_NAME DatabaseName.DBO
    
    SELECT * FROM $(VAR_DB_NAME).tableName
    If I try to do:
    Code:
    CREATE FUNCTION $(VAR_DB_NAME).FunctionName
    I'm getting an error:

    Code:
    CREATE/ALTER FUNCTION' does not allow specifying the database name as a prefix to the object name
    How can I check if function exists and create/drop it using same variable?

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    20
    you cannot include the database name in the CREATE statement , try that code :
    Code:
    :SETVAR VAR_DB_NAME DatabaseName
    :SETVAR VAR_SCHEMA_NAME dbo
    
    use $(VAR_DB_NAME)
    go
    
    create function $(VAR_SCHEMA_NAME).foo()
    returns int
    as 
    begin
    return (1)
    end
    go

+ Reply to Thread

Bookmarks

Posting Permissions

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