tags:

views:

43

answers:

2

If I want to see which values from an Excel spreadsheet column don't match values in a table, I can easily create a table with Bulk Import. Is there a simpler way? EG, I want to do a query like:

select into #temp from ('a', 'b', 'c') as 'Id'
select * from #temp where Id not in (select Id from MyTable)
+1  A: 

I would recommend using this UDF to parse your list into a table. Then you should be able to do the following:

SELECT * INTO #temp FROM dbo.udf_List2Table( 'a,b,c', ',') 
SELECT * FROM #temp WHERE item NOT IN (SELECT Id FROM MyTable)
Abe Miessler
You have a syntax error - the `INTO` statement must come before `FROM`
Ed Harper
Thanks for this. I fixed some syntax errors for you. This is good, but doesn't seem to play nice with newlines in the string, so it's a bit of a pain to paste in from an Excel column.
RossFabricant
Thanks Ed. Fixed. @rossfabricant - I could see the new line causing problems. Could you do some cleanup on your csv file before you past the comma seperated values into your query? If you have Notepad++ this link might help you accomplish this: http://notepad-plus.sourceforge.net/uk/newlineFindReplace-HOWTO.php
Abe Miessler
+1  A: 

Also, I've been using the additional column in Excel with bunch of CONCATENATE.TEXT commands to create the INSERT statements. This column alone, copied into the text file, is your script!

htaler
Thanks, good idea. However, it would be easier to be able to use a simpler formula or no formula at all when copying from Excel.
RossFabricant