Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT DISTINCT

Status
Not open for further replies.

DB2Problem

Programmer
Oct 17, 2002
53
US
Hi,

I am having a shell program which is connecting to db2 and running a SELECT DISTINCT sql statement. I need to get the result of the SELECT DISTINCT statement in a FILE which at present is coming on the console.

Please suggest with code snippet.

Thanks
 
I have created a file called query containing the sql.

Used cat to show you the contents of query.

Ran the file by entering query, the results coming out on the screen.

Ran the file again but this time re-directed the output to a file called out.

Used cat to show you the contents of out.

db2live@unix1:/db2/db2live/users/greg> cat query
db2 "select count(*) from sysibm.sysdummy1 "
db2live@unix1:/db2/db2live/users/greg> query

1
-----------
1

1 record(s) selected.

db2live@unix1:/db2/db2live/users/greg> query>out
db2live@unix1:/db2/db2live/users/greg> cat out

1
-----------
1

1 record(s) selected.

db2live@unix1:/db2/db2live/users/greg>

 
Thanks Greg for your code snippet,

I tried to work the same way, but my problem is i am connecting to DB2 from a Shell program and then run the SELECT DISTINCT query.

Part of Shell Script looks like this --
:
db2 connect to <<database>> user <<userid>> using <<password>>
db2 &quot;SELECT DISTINCT sql query goes here&quot;
:

I need to get the result of SELECT DISTINCT statement in a file.

Appeciate if you can further suggest something on this

 
db2 connect to <<database>> user <<userid>> using <<password>>
db2 &quot;SELECT DISTINCT sql query goes here&quot; > out
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top