Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Use Condition in SQL

 
Dhiraj Srivastava
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here this query gives location of first occurance of letter 'A' in the name.

select
(posstr(t1.NAME,'A')) as Location, t1.Name from vista.VFZPVACCOUNTANT t1


------------ OUTPUT ------------------

LOCATION NAME
----------- --------------------------
0 test
14 Kuhn Handels AG

-------------------------------------
-------------------------------------

I want to select only "Non Zero" location records. Means There should be atleast one 'A' or 'a' in the name.

So that in the output there should be only second record.

I am working on Db2 database Can ne one help.

Thanks in advance,
Dhiraj Srivastava
 
Mukhtiar Ahmed
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please user where clause in your query

select
(posstr(t1.NAME,'A')) as Location, t1.Name from vista.VFZPVACCOUNTANT t1

where Location > 0
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely you mean

. . . WHERE location >= 0

?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic