Page 1 of 1

Select From db2

PostPosted: Mon Sep 24, 2012 6:25 pm
by vkumarg3
Hi all,

I am new to db2. so please help. This is my issue.

Field1 Field2

XXXXXX 'AB' OR 'CD' OR 'EF'
YYYYYY 'GH' OR 'IJ'


Is it possible to fetch field1 using field2? Like only specifying 'AB' in where clause. Not full values of tables as mentioned in table.

If so, please specify query.

Thanks in advance.

Re: Select From db2

PostPosted: Mon Sep 24, 2012 6:31 pm
by NicC
What happened when you tried a test in SPUFI?

Re: Select From db2

PostPosted: Mon Sep 24, 2012 6:42 pm
by vkumarg3
I dont know how to write query to meet that condition. So only asked you NicC.

If you give any idea , I will test in spufi.

Re: Select From db2

PostPosted: Mon Sep 24, 2012 7:38 pm
by dick scherrer
Hello,

From what you have posted, i do not understand what you want your query to do.

Please do a more complete job showing what you "have" as input in the table(s) / rows(s) and what you want returned when the query runs correctly.

Use the Code Tag to preserve alignment and improve readability. Practice using the Preview function before Submitting.

Re: Select From db2

PostPosted: Mon Sep 24, 2012 7:38 pm
by vkumarg3
SELECT FIELD1
FROM TABLE-NAME
WHERE FIELD2 LIKE '%AB%' OR 'AB%'.

From my understanding I wrote this query. Whether It will work?

Help me. Thanks

Re: Select From db2

PostPosted: Mon Sep 24, 2012 7:39 pm
by vkumarg3
ok dick. . I used to be. But Missed somehow. Wait i will explain cleary.

Re: Select From db2

PostPosted: Mon Sep 24, 2012 8:03 pm
by vkumarg3
dick scherrer wrote:Hello,

From what you have posted, i do not understand what you want your query to do.

Please do a more complete job showing what you "have" as input in the table(s) / rows(s) and what you want returned when the query runs correctly.

Use the Code Tag to preserve alignment and improve readability. Practice using the Preview function before Submitting.



My Input file(test) is this:

FILD1  |FIELD2
------- ---------------------------------
XXXX   |'AB' OR 'CD' OR 'EF'
YYYY   |'GH' OR 'IJ'
ZZZZ   |'KL' OR 'AB'
-------------------------------------------

Query I written :

SELECT FILD1
  FROM TEST
 WHERE FIELD2 LIKE '%AB%' OR 'AB%'.
Code'd
Will this query give Output XXXX and ZZZZ? This is my assignment. Dont have any Mainframe IDs to test. Once I get approval only . I can proceed further.

Sorry dick Even if i have given spaces also, It s coming lik that only.

Re: Select From db2

PostPosted: Mon Sep 24, 2012 8:47 pm
by dick scherrer
Hello,

Your data has been "Code'd". You too can do this in the "Full Editor".

At the top and bottom of the page is a link to "IBM Manuals". Look at the SQL Language reference and search for LIKE.

Why does the data in field2 contain quotes and ORs?

Is your input in "files" or database tables? It is most important to use proper terminology (i.e. sql queries are not run against files).

Re: Select From db2

PostPosted: Mon Sep 24, 2012 8:52 pm
by NicC
Unless you have AB embedded in your data you can use
WHERE FIELD2 = 'AB'

To use the code tags use the full editor (click on POST REPLY not Quick Reply, higlight the text to be 'coded' and click on the Code button. Then use the Preview button instead of the Submit button. If it looks OK now click on the Submit button otherwise scroll, as necessary, to the input panel and continue editing/previewing.