|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using Conditionals... Question (IF statements)
Hello there, I'm rather new to the SQL database scripting but I've had no trouble with basic selects/updates but my main issue right now is that I'm not sure how to use Conditional statements for my current task.
The table I need to get/insert information to is located on a database called BOS the table I'm testing the conditional on is ORDERSOURCES I want to make an if statement that goes like this IF "a value of 8888 does not exist" THEN INSERT INTO ORDERSOURCES VALUES ('THIS', '8888','THAT') ELSE do nothing END IF I'm just not sure how to have my if statement point to that table and check to see if the values 8888 exist(the value name is called code) I was trying something like IF @ORDERSOURCES WHERE CODE = '8888' THEN INSERT but its not working. Because in my program as soon as you set the order to not be for internet it removes it from the table so I can't just check for a certain value and then say thats not right and change it. Hopefully you guys aren't as confused as me after reading what I wrote. Please if you have any insight I would appreciate it so much. Thank you. |
|
#2
|
|||
|
|||
|
I think I need it to iterate thru all the codes and check if the code is there. And if the code isn't there insert it. But I'm just having a hell of a time getting it to select/look for the right values.
|
|
#3
|
|||
|
|||
|
Jeez I feel stupid. Ok
IF NOT EXISTS (SELECT * FROM <TABLE> WHERE <VALUE> = 'THIS') but how do I return text saying "this is already here no worries" |
|
#4
|
|||
|
|||
|
Guess I can just use :
SELECT 'Already existing' |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Using Conditionals... Question (IF statements) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|