Dynamic sql where contents

Hi all,

I need to add the contents from a file into a sql stament in the where clause.

file1:

id
1
2
3
10
11
...

script should look like :

select name from tab_user tus where tus.id in (1,2,3,10,11..)

any ideas or suggetions will be appreciatte.

Thanks in advance.

Hi
You can try something like this:

awk 'NR!=1{if (a) a=a","$0;else a=$0;}END{print "select name from tab_user tus where tus.id in (",a,")";}' file1

Thanks
Guru.

$ for i in `awk 'NR>1 {print $1}' file1`
do
j=$j,$i
done
$ k=`echo $j | cut -c2-`
$ query="select name from tab_user tus where tus.id in ($k)"
$ echo $query
select name from tab_user tus where tus.id in (1,2,3,10,11)
$ 
$
$
$ cat f9
id
1
2
3
10
11
$
$
$ perl -lne 'push @x, $_ if $.>1;
>            END {print "select name from tab_user tus where tus.id in (",join(",",@x),")"}' f9
select name from tab_user tus where tus.id in (1,2,3,10,11)
$
$

tyler_durden

#!/bin/bash
{   read I
    S="select name from tab_user tus where tus.$I in ("
    while read I; do S+="$I,"; done
    S="${S%,})"
} < file1
echo "$S"

Thank you all, I will have a look at the scripts.

i use the following work-around it does the trick.

cat select.txt list_ids.txt end_query.txt > query.sql

Thank you all