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

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • 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