| Author |
Topic |
|
brendalisalowe
Constraint Violating Yak Guru
269 Posts |
Posted - 2004-11-08 : 14:05:39
|
When I run this:Select CaseNumber from tblParadoxWhere CaseNumber = '011-281226' I get no cases, which is what I want.When I run this:Select CaseNumber from tblWebWhackerWhere CaseNumber = '011-281226' And I get 1 case, is what I want.But when I run this, I don't get anything:Select CaseNumber from tblWebWhackerWhere Not Exists (Select CaseNumber From tblParadox)Order by CaseNumber Shouldn't it show the cases that are in tblWebWhacker and not in tblParadox?BrendaIf it weren't for you guys, where would I be? |
|
|
DustinMichaels
Constraint Violating Yak Guru
464 Posts |
Posted - 2004-11-08 : 14:10:06
|
The stuff inside of the exists is wrong. Your where clause could be translated to "Where NOT anything in tblParadox".In order for it to work you need to reference the web whacker table inside of the exists query.Select CaseNumber from tblWebWhackerWhere Not Exists (Select * FROM tblParadox WHERE tblParadox.CaseNumber = tblWebWhacker.CaseNumber)Order by CaseNumber Dustin Michaels |
 |
|
|
VIG
Yak Posting Veteran
86 Posts |
Posted - 2004-11-08 : 14:13:47
|
| Select CaseNumber from tblWebWhacker wWhere Not Exists (Select CaseNumber From tblParadox p where p.CaseNumber=w.CaseNumber )Order by CaseNumberor Select CaseNumber from tblWebWhackerWhere CaseNumber Not IN (Select CaseNumber From tblParadox)Order by CaseNumberor Select CaseNumber from tblWebWhacker wLEFT JOIN tblParadox pON w.CaseNumber=p.CaseNumberWHERE p.CaseNumber IS NULL |
 |
|
|
brendalisalowe
Constraint Violating Yak Guru
269 Posts |
Posted - 2004-11-08 : 14:20:24
|
| Thanks! That is perfect!BrendaIf it weren't for you guys, where would I be? |
 |
|
|
brendalisalowe
Constraint Violating Yak Guru
269 Posts |
Posted - 2004-11-08 : 15:45:55
|
One more question. If I wanted to insert the data into a new table, how would I do it? This doesn't work:INSERT INTO tblCurrentMonth (CaseNumber) Values (Select CaseNumber from tblWebWhacker Where not exists (Select CaseNumber From tblParadox Where tblParadox.CaseNumber = tblWebWhacker.CaseNumber) And refund > 1000 Thanks!BrendaIf it weren't for you guys, where would I be? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-11-08 : 15:49:17
|
| INSERT INTO tblCurrentMonth (CaseNumber) Select CaseNumber from tblWebWhacker Where not exists (Select CaseNumber From tblParadox Where tblParadox.CaseNumber = tblWebWhacker.CaseNumber) And refund > 1000Tara |
 |
|
|
brendalisalowe
Constraint Violating Yak Guru
269 Posts |
Posted - 2004-11-08 : 17:56:50
|
| Hi TaraWhy do you not use VALUES?BrendaIf it weren't for you guys, where would I be? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-11-08 : 17:59:17
|
From BOL:quote: Inserting a Row Using INSERT...ValuesThe VALUES keyword specifies the values for one row of a table. The values are specified as a comma-separated list of scalar expressions whose data type, precision, and scale must be the same as or implicitly convertible to the corresponding column in the column list. If a column list is not specified, the values must be specified in the same sequence as the columns in the table or view.For example, this statement inserts a new shipper into the Shippers table using the VALUES clause:INSERT INTO Northwind.dbo.Shippers (CompanyName, Phone) VALUES (N'Snowflake Shipping', N'(503)555-7233')A column list is required for this insert because the ShipperID column has the IDENTITY property; therefore, values cannot be inserted into it.
quote: Inserting Rows Using INSERT...SELECTThe SELECT subquery in the INSERT statement can be used to add values into a table from one or more other tables or views. Using a SELECT subquery also lets more than one row be inserted at one time.This INSERT statement inserts into a separate table some of the data from all the rows in titles whose type is modern cooking:USE pubsINSERT INTO MyBooks SELECT title_id, title, type FROM titles WHERE type = 'mod_cook'The select list of the subquery must match the column list of the INSERT statement. If no column list is specified, the select list must match the columns in the table or view being inserted into.Another use of the INSERT...SELECT statement is to insert data from a source outside of Microsoft® SQL Server™. The SELECT in the INSERT statement can: Reference a remote table on a linked server by using a four-part name. For more information, Identifying a Data Source Using a Linked Server Name.Reference a remote table using OPENROWSET. For more information, see Identifying a Data Source Using the Ad Hoc Name.Use the result set of a query executed on a remote server. For more information, see Using Pass-through Queries as Tables.
Tara |
 |
|
|
brendalisalowe
Constraint Violating Yak Guru
269 Posts |
Posted - 2004-11-09 : 14:43:13
|
| Thanks Tara!BrendaIf it weren't for you guys, where would I be? |
 |
|
|
|