|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Using Where in a Insert statement
Is is possible to use a Where Clause in a Insert statement in MS SQL? I keep getting a syntax error near 'Where'. Is there something wrong with this?
Insert INTO CPU (CPUNumber, Name, MaxClockSpeed, SystemNetName) Values('CPU2', 'Intel', '2392', 'TWEETY') Where 'CPU2' NOT IN (Select CPUNumber from CPU) I want to insert into the cpu table as long as what I am inserting is not already in the table. Desparate. Thanks, Laura |
|
#2
|
|||
|
|||
|
Well, not like this - a WHERE clause only comes after a SELECT.
Perhaps should you try: if not exists (select * from CPU where CPUNumber = 'CPU') then INSERT INTO CPU .... With regards, Martijn Tonies Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL Server. Upscene Productions http://www.upscene.com
__________________
Martijn Tonies Database Workbench: developer IDE for Firebird, MySQL, InterBase, MSSQL Server and Oracle Upscene Productions http://www.upscene.com |
|
#3
|
|||
|
|||
|
Code:
Insert INTO CPU (CPUNumber, Name, MaxClockSpeed, SystemNetName) SELECT 'CPU2', 'Intel', '2392', 'TWEETY' -- (or field names, if that's what you really want to insert) FROM CPU WHERE CPUNumber NOT IN 'CPU2' Nevermind. I misunderstood the question. |
|
#4
|
||||
|
||||
|
Quote:
are you inserting values, or using a select? |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Using Where in a Insert statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|