INSERT INTO With Condition

  • Hi, i was able to insert into table 'FilesPath' two values (a,b) but if value 'a' not exist.

    This is my SQL query:

    INSERT INTO FilesPath

                          (Path,Destination)

    VALUES     (@a,@b)

    WHERE     0 =

                              (SELECT     COUNT(*)

                                FROM          filespath

                                WHERE      Destination = @a)

    there is one error on WHERE statement.

    How i will solve this problem???

    Thanks 4 All.

  • Why not recast this as a conditional insert?

    if not exists (SELECT destination FROM filespath WHERE Destination = @a)

    begin

     INSERT INTO FilesPath (Path,Destination)

     VALUES     (@a,@b)

    end

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Thank a lot. this is better from my code and it is work excellent.

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

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