Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. sp_executesql

sp_executesql

Scheduled Pinned Locked Moved Database
helpsharepointsysadminquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SVb net
    wrote on last edited by
    #1

    i need to declare variables dynamic , then this my code for make that .but i can't used why???????????????????? Declare @TableName Char(100) Set @TableName = 'Ar_PromotionDetails' --{Columns}PromotionId Declare Cur_Sys_DataAdapterTable Cursor For Select Cln.name As [Columns] , Type.Name Types , Cln.Length , Cln.xprec , Cln.xscale From sysobjects Obj inner join syscolumns Cln On Obj.Id = Cln.id Inner join systypes Type On Type.xtype = Cln.xtype Where obj.id = object_Id(@TableName) Declare @ColumnName char(120) , @TypeName char(120) Declare @Length SmallInt Declare @xprec Tinyint , @xscale Tinyint Open Cur_Sys_DataAdapterTable Fetch Next From Cur_Sys_DataAdapterTable Into @ColumnName , @TypeName , @Length ,@xprec , @xscale Declare @DeclareVariable NChar(300) Set @DeclareVariable =N'' While @@fetch_status = 0 begin if ( LOWER(Rtrim(@TypeName)) in ( 'datetime' , 'bit' , 'int' , 'bigint', 'smallint' , 'tinyint' , 'bigint' , 'smalldatetime' , 'float') ) Set @DeclareVariable = Rtrim(@ColumnName) + space(5) + Rtrim(@TypeName) else if ( LOWER (Rtrim(@TypeName)) in ('numeric' , 'decimal' ) ) Set @DeclareVariable = Rtrim(@ColumnName) + space(5)+Rtrim(@TypeName) + N'('+ Rtrim(@xprec)+ N',' + Rtrim(@xscale) +N')' else Set @DeclareVariable = Rtrim(@ColumnName) + space(5)+Rtrim(@TypeName)+N'(' + Rtrim(@Length) + N')' Set @DeclareVariable = N'Declare @@' + @DeclareVariable + Char(13) Exec sp_Executesql @DeclareVariable print 'load ok...' Fetch Next From Cur_Sys_DataAdapterTable Into @ColumnName , @TypeName , @Length , @xprec , @xscale End Close Cur_Sys_DataAdapterTable deallocate Cur_Sys_DataAdapterTable Select @@PromotionId --when i use this command make error (Server: Msg 137, Level 15, State 2, Line 62 Must declare the variable '@@PromotionId'.) how i can resolve this problem?

    123

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups