Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2003
    Posts
    14

    Post Unanswered: Another Problem with variables

    I have this...

    declare
    @variable int

    create table #tmp_datos
    ( variable int null )

    insert into #tmp_datos
    exec sp_prueba_era

    select @variable = variable
    from
    #tmp_datos

    select @variable

    drop proc sp_prueba_era
    go

    create proc sp_prueba_era @variable int output
    as
    declare
    @cmd varchar(250)

    are there other way to do this??

  2. #2
    Join Date
    Nov 2002
    Posts
    94
    are you able to connect to your server using isql ?

  3. #3
    Join Date
    Jan 2003
    Posts
    14
    Yes, but I need to pass dinamically the name of the server, by this I'm using strings and exec...

    But the original query it's this...

    Select @var = Select 1 from xx

    I need to pass this to string...

  4. #4
    Join Date
    Nov 2002
    Posts
    94
    Originally posted by ramshree
    are you able to connect to your server using isql ?
    Not clear what you are trying to do.

    but this works :

    declare @var char(100)
    select @var = 'select * from sysobjects'
    exec (@var)

    -

  5. #5
    Join Date
    Jan 2003
    Posts
    14
    I'm trying to store a value in a variable into select statement, but my select statement it's a string that I'm going to execute with exec clause..., so I can't to do this...

    declare
    @variable int,
    @cmd varchar(100)

    select @cmd = "select @variable = 20"
    exec (@cmd)

    because @variable it's not a defined variable..., so how can I do for make a string like this...

  6. #6
    Join Date
    Jan 2003
    Posts
    14

    Question

    Maybe there is something, i haven't understood, but why is it so important, that the select is stored in the string?

  7. #7
    Join Date
    Jan 2003
    Posts
    5

    Re: Another Problem with variables

    Hi,
    Hope this is wat u want--
    here i am assigning the count of the number of records to the variable @varCountTable. but the whole string has to be executed in EXEC().
    Personalize it to ur needs--
    SET @varSelectString = N'SELECT @varCountTable = COUNT(*) FROM CPGSTAGEDB.DBO.' + @varTableName
    EXEC SP_EXECUTESQL @varSelectString, N'@varCountTable nvarchar(50) OUTPUT',@varCountTable = @varCountTable OUTPUT

    Regards,
    Ramya




    Originally posted by ericka
    I have this...

    declare
    @variable int

    create table #tmp_datos
    ( variable int null )

    insert into #tmp_datos
    exec sp_prueba_era

    select @variable = variable
    from
    #tmp_datos

    select @variable

    drop proc sp_prueba_era
    go

    create proc sp_prueba_era @variable int output
    as
    declare
    @cmd varchar(250)

    are there other way to do this??

Posting Permissions

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