View previous topic :: View next topic
|
Author |
Message |
Tushar14
New User
Joined: 30 Jun 2012 Posts: 2 Location: India
|
|
|
|
I have requirement wherein a column of DB2 table could have blanks or values upto 2 digits.I need to fetch those records which has both blanks and values associated with that column.
Emp ID:-
--
99
11
--
11 --
-- 22
I need to write query which could fetch only last 2 records as mentioned in Emp ID. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
So you have to fetch only last two records which has spaces or values upto two digits??
or Explain the requirement better |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Any chance you could share the definition of the column with us? DB2 tables have rows not records. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
is it only one column - emp_ID
or
is it two columns - emp and ID?
assuming that it is one column - emp_ID
then
what is the ddl for the column?
char(2)
NULLABLE
??
answer those questions
denoted in BOLD and underlined, please. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello and welcome to the forum,
As has been mentioned, your request is quite unclear. .
Quote: |
Emp ID:-
--
99
11
--
11 --
-- 22 |
Why do some values have 2 bytes and others 4 bytes?
If you post what has been requested and also exp[lain what this is to accomplish, someone may have a suggestion. |
|
Back to top |
|
|
Tushar14
New User
Joined: 30 Jun 2012 Posts: 2 Location: India
|
|
|
|
Guys its only one column.
Yes its Char (2).
Let me explain it more;
Col 1 Col 2
A 99
B 12
C 45
A --
Now I want to write a query which fetches 99 and blanks from col2 for A only.
Thanks much for your replies !!! |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Tushar,
Looks to me a straight forward problem
What did you try and what went wrong with the query?
Or is there still some implicit requirement you are yet to share? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
what if you don't have a column with two blanks "bb" (b = spaces)
what if you have
b1
bA
1b
Ab
and can the column be NULL?
short of accounting for NULL,
you could UNION ALL two selects
each looking for a space in the col
i.e. POSSTR(emp_ID,' ') > 0/= 0
then sorting descending, each FETCH FIRST ROW ONLY.
and, pleassssssssssssse. do not dare show exasperation with our confusion. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please review your last post.
You mention it is "only one column", but the sample data shows 2 . . .
How does your second post relate to the first?
You need to do a much better job of explaining what you "have" and what you want as a result when this new process is run.
Showing the "input" and the output wanted will help. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Tushar,
Assuming two hyphens (-) represent null values in the column 2,
Please try-
Code: |
SELECT * FROM <table-name>
WHERE
COL1 = 'A' AND
(COL2 = '99' OR COL2 IS NULL) |
Maybe the beginner's forum is better suited for your needs. If the column 2 values really are spaces then you will need to change the where clause accordingly. |
|
Back to top |
|
|
|