max ids of two tables - compare

  • Hi there,

    I have a two tables table1 and table2 and both containing ID column. I want to find max(ID) of table1 and max(ID) of table2 and if both max IDs are same, I will call a C# program using .exe.

    Is this possible in a single SQL statement in a batch file?

    Create table table1(ID int not null,

    CONSTRAINT [pkid1] PRIMARY KEY CLUSTERED

    (

    [Id] ASC

    ));

    Create table table2(ID int not null,

    CONSTRAINT [pkid2] PRIMARY KEY CLUSTERED

    (

    [Id] ASC

    ));

    Thanks

    rash

  • Is this what you want?

    if ((select max(ID) from table1)=(select max(ID) from table2)) exec xp_cmdshell c#program ;

    Tom

  • This is what I made changes

    if ((select max(ID) from table1)=(select max(ID) from table2)) exec xp_cmdshell `sqlcmd -E -S "DBNAME\INSTANCE1" -h-1 -Q ` (

    echo executed commandshell

    start "" "D:\firstpgm\bin\Debug\firstpgm.exe"

    goto end

    )

    :end

    echo END

    Not sure if this is correct way of invoking.

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

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