×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Check for string and count

Check for string and count

Check for string and count

(OP)
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

RE: Check for string and count

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

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com

RE: Check for string and count

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

RE: Check for string and count

(OP)
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

RE: Check for string and count

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

RE: Check for string and count

(OP)
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

RE: Check for string and count

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

RE: Check for string and count

(OP)
I am using ASP and Pervasive SQL.  I even tried with various string functions and it gives type mismatch.

RE: Check for string and count

(OP)
I got it working

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close