SQL Help ?!?!

Um what are you trying to do here with these update statements.
Best way here would be to

insert into Table_name (col1)
select col2
from dbo.TestTable
where col1 != col2

enjoy
 
facepalm! didn't see second page
Was wondering why you were bothering with update statements
ya best would be from Messugga
INSERT INTO Test1(A)
SELECT Test2.B
FROM Test2
WHERE Test2.B
NOT IN
(SELECT Test1.A FROM Test1)
 
Okay lol, need a little more help. If I'm trying to select rows where tableA.column1's entry exists in tableB.Column3 , how would I set this out as a Select Query?

Tried
Code:
WHERE Number LIKE [dbo].[Number.Filter].[NumberCheck]

but this isn't working.
 
Try an nested query


EG : Where Number IN (select number from dbo.number.filter)
 
Code:
WHERE EXISTS (SELECT * FROM [Test_Database].dbo.[Number.Filter] as O
				WHERE M.PurchaseNumber LIKE CONCAT('%', O.Number))

Nested query works 100% but if I wanted to use LIKE with a Wild Card for all entries ending in the Numbers in the Filter table thwis doesn't work at all.

Also how would I use that Nested query to compare Dates and only select those that occur on said days (holidays). Any help would be appreciated.
 
Hmmmm let me bugger around a lil bit with some stuff on my side..

Any possibility that you could give me a sample of the data you're playing with and how you want the results to come out as.
 
Maybe provide the tables' scripts? It'd help us to help you. Also, a more thorough description of what you want to do now, would prove useful. It's not a particularly complex problem though, so we should be able to sort you out quickly.
 
Ok guys, I'm trying to see if any sales went through on public holidays and such. Test Data below.

http://ifile.it/2ibhtxl

http://ifile.it/spg1fj4

Regarding the problem with Like and checking the value in a different table, it got it to work by adding a '%' in the SQL Table (Hard-coding it, which isn't exactly what I want).
Will add a pic of the Filter Table that I'm using for the below query in a bit.

Code:
SELECT TOP 20 
     [Sales Consultant]
      ,[Sale Date]
      ,[ID] 
FROM [Sales].[dbo].[TestSales] as S
WHERE S.ID like (SELECT [FilterValue] FROM [Sales].dbo.[TestSales] 
						WHERE [FilterField] = 'ID')
 
Ok guys, I'm trying to see if any sales went through on public holidays and such. Test Data below.

http://ifile.it/2ibhtxl

http://ifile.it/spg1fj4

Regarding the problem with Like and checking the value in a different table, it got it to work by adding a '%' in the SQL Table (Hard-coding it, which isn't exactly what I want).
Will add a pic of the Filter Table that I'm using for the below query in a bit.

Code:
SELECT TOP 20 
     [Sales Consultant]
      ,[Sale Date]
      ,[ID] 
FROM [Sales].[dbo].[TestSales] as S
WHERE S.ID like (SELECT [FilterValue] FROM [Sales].dbo.[TestSales] 
						WHERE [FilterField] = 'ID')

Okay, just to get some clarity for my own sake, the FilterValue is the public holidays? In that case, I don't think what you currently have will work as you think. Instead, I'd change the format of the date to one that's simpler to compare (You can Google on how to format dates). Also, I'm not positive about this, but "LIKE" there will only work for one result, which defeats the point of the second select statement anyway. Instead, use "IN". That should sort you out.
 
@Messugga
The code shown above was for testing the ID field.
For the Date, I was thinking it would be something like :
Code:
SELECT TOP 20 
       [Sales Consultant]
      ,[Sale Date]
      ,[ID] 
FROM [Sales].[dbo].[TestSales] as S
WHERE S.Date = [Sales].dbo.[Holidays].

Problem is I never get any results and the formatting of the dates can't be changed on the TestSales table which might also be a problem.
 
Top
Sign up to the MyBroadband newsletter
X