Results 1 to 2 of 2

Thread: SELECT to produce results usign an external file as filter

  1. #1
    Join Date
    Jan 2004
    Posts
    7

    SELECT to produce results usign an external file as filter

    Can I use Query Analyser or Query on Enterprise Manager to SELECT from a table of records and use and external file (txt file on c drive) as a filter.

    I.e txt file has 5 records with 2 fields.

    Table has 2000 records with 10 fields.

    I need to select records from table with field 1 not matching field 2 of any of the five records in the text file.

    Please provide guidance and help.

    Thanks

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    --Say u have a table like this
    create table mytable123 (id int, name varchar(100), contact int, address varchar(100))
    insert into mytable123 select 1,'B123',123,'main st'
    insert into mytable123 select 2,'w123',13,'elm st'
    insert into mytable123 select 3,'e13',23,'water st'
    insert into mytable123 select 4,'Bt3',1,'polo st'
    insert into mytable123 select 5,'y1iu',3,'nike st'
    insert into mytable123 select 6,'B123',5123,'king st'

    --Say you have a text file c:\mytext.txt like below
    A123, 1343.43
    A3, 2232.45
    B123, 3454.46
    B2, 4565.84
    Bx, 5067.46

    --you can do this
    --drop table #temp1
    create table #temp1 (name varchar(10), salary money)
    BULK INSERT #temp1
    FROM 'c:\mytext.txt'
    WITH
    (
    FIELDTERMINATOR = ',',
    ROWTERMINATOR = '\n'
    )
    --select * from #temp1
    select * from mytable123 where name not in (select name from #temp1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •