Results 1 to 4 of 4

Thread: Syntaxis error

  1. #1
    Join Date
    Jan 2003
    Posts
    14

    Question Unanswered: Syntaxis error

    I have a problem...
    I'm trying to do this...

    declare @cmd varchar(200)
    @cmd = 'Select 1 from xx'
    if exist (exec(@cmd))
    begin
    'my code'
    end

    but I have an error..., do you know why??

  2. #2
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    first, when assigning a value to a variable you need to use "set" or "select". second, EXISTS can only take a SELECT statment for an argument.
    Last edited by Paul Young; 01-29-03 at 08:43.
    Paul Young
    (Knowledge is power! Get some!)

  3. #3
    Join Date
    Jan 2003
    Posts
    14
    Well, I forgot to write the set statement, but I'm using it..., and if I can not use an exec statement, do you know other way to do a string with my select statement??

  4. #4
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    If I understand what you are trying to do, how about this?

    Code:
    create table #tmp(f1 int)
    declare @cmd varchar(200)
    set @cmd = 'select 1'
    truncate table #Tmp
    insert into #tmp exec (@cmd)
    if exists(select * from #tmp) begin
       print 'EXISTS!'
    end
    drop table #Tmp
    Paul Young
    (Knowledge is power! Get some!)

Posting Permissions

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