MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 30th, 2009, 07:23 PM
Rawnzimm Rawnzimm is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 13 Rawnzimm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 41 m 58 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old June 30th, 2009, 07:27 PM
Rawnzimm Rawnzimm is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 13 Rawnzimm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 41 m 58 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old June 30th, 2009, 07:37 PM
Rawnzimm Rawnzimm is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 13 Rawnzimm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 41 m 58 sec
Reputation Power: 0
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"

Reply With Quote
  #4  
Old June 30th, 2009, 08:11 PM
Rawnzimm Rawnzimm is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 13 Rawnzimm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 41 m 58 sec
Reputation Power: 0
Guess I can just use :

SELECT 'Already existing'

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Using Conditionals... Question (IF statements)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
Stay green...Green IT