Groups | Blog | Home
all groups > sql server (alternate) > march 2004 >

sql server (alternate) : Help With Query using values out of a CSV File?


Cliff Roman
3/18/2004 10:55:09 PM
I apologize, I am used to using PHP and MySQL so I am a little out of what I
am used to

At work they asked me to help them with something and thus I am here asking
for your assistance :)

We have a Database that we use with SQL 2000

In this database is a very simple table

UserID, EmpNum, FirstName, LastName

I have a comma delimited file of about 8000 Employee Numbers.

I need to run a query to get the UserID, FirstName and LastName for those.
Of course a 1 at a time query is no problem, but I have NO CLUE how to go
about getting it to run a query on all of the Emploee Numbers that are in
this CSV file and compiling a report

Any assistance is appreciated

Thanks

Erland Sommarskog
3/18/2004 11:07:57 PM
Cliff Roman (cliffno_spamnone@theromans.us) writes:
[quoted text, click to view]

You could build a string from the file, and then use the function
iter_intlist_to_table on
http://www.sommarskog.se/arrays-in-sql.html#iter-list-of-integers.


--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
PromisedOyster NO[at]SPAM hotmail.com
3/19/2004 5:46:11 AM
[quoted text, click to view]

An alternative would be to:

(a) Create a database table EmployeeNumbers to store these employee numbers

(b) Load the csv file into the database using bcp, dts or SQL script

(c) Then simply run a query to join the tables, eg
select
e.UserID
,e.FirstName
,e.LastName
from
Employees e,
,EmployeeNumbers en
where
AddThis Social Bookmark Button