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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for string and count

Status
Not open for further replies.

sandyas

Programmer
Apr 20, 2006
31
US
Hi,
I have to check for conditions in the select statement. The coulumn to be checked is string

select.....................,substr(COC,1,1) as nr FROM .........................

How to use case statement while checking for substrings. The field COC contains either N or R.

Thanks
 
What exactly are you trying to do?
What have you tried and what results have you seen?


Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
There is an IF-THEN-ELSE scalar funciton. Try something like:

SELECT IF(SUBSTR(COC,1,1) = 'N', 'Is N', 'Is Not N') as nr FROM tbl
...



Linda
Pervasive Software
 
I need to increment values in the IF statement like

SELECT IF(SUBSTR(COC,1,1) = 'N', n=n+1, r=r+1) FROM tbl

How do I go about it.
Thanks
 
In your example, are n and r fields in the table?

You can't update within a select list, you can only construct an expression to return to the application issuing the select.

Sounds like maybe you need to work in the context of a stored procedure where you can loop and select records one at a time and maintain local variables.

Linda
Pervasive Software
 
I basically print COC which is a field in the table and need to increment the value of n and r depending on the value of COC. I need to display the value of n and r at the end of the report. The values of the field COC are 'N' and 'R'. I need the display to be as follows:

COC
----
N
N
R
N

N = 3 R = 1
 
What kind of application are you using to generate this report? Are you developing a custom application or using some kind of SQL tool?


Linda
Pervasive Software
 
I am using ASP and Pervasive SQL. I even tried with various string functions and it gives type mismatch.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top