Execution Error

  • when i execute the following procedure after creating it i am getting error below.

    "alter proc usp_get

    as

    begin

    declare @sql varchar(100)='create view dbo.vw_select asselect '+char(39)+'2009-01-01'+Char(39)+' As a'

    print @sql

    exec @sql

    end

    go"

    exec usp_get

    Error Msg

    Msg 2812, Level 16, State 62, Procedure usp_get, Line 6

    Could not find stored procedure 'create view dbo.vw_select asselect '2009-01-01' As a'.

    Help?

    I am created procedure which creates a view in it

    Regards

    Ramu

  • Hi,

    Try this

    alter proc usp_get

    as

    begin

    declare @sql Nvarchar(100)

    select @sql = 'create view dbo.vw_select as select '+char(39)+'2009-01-01'+Char(39)+' As a'

    print @sql

    exec sp_executesql @sql

    end

  • Thanks it worked.

    arun.sas (8/17/2009)


    Hi,

    Try this

    alter proc usp_get

    as

    begin

    declare @sql Nvarchar(100)

    select @sql = 'create view dbo.vw_select as select '+char(39)+'2009-01-01'+Char(39)+' As a'

    print @sql

    exec sp_executesql @sql

    end

  • yet another way to skin the cat - no sp_executesql

    alter proc usp_get

    as

    begin

    declare @sql varchar(100)

    select @sql='create view dbo.vw_select as select '+char(39)+'2009-01-01'+Char(39)+' As a'

    print @sql

    exec (@sql)

    end

    go

    exec usp_get

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply