473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SUBSTRING in where clause

maxamis4
295 Expert 100+
Hello folks,

I have the following substring statement I am using but I want to filter by my substring, can anyone help


Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT     last_name, SUBSTRING(alternate_identifier, 5, 2) AS Contractor
  3. FROM         ca_contact
  4. WHERE     (contact_type = 2308) AND (inactive <> 1)
  5.  
  6.  

if i try this it fails with parsing errors


Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT     last_name, SUBSTRING(alternate_identifier, 5, 2) AS Contractor
  3. FROM         ca_contact
  4. WHERE     (contact_type = 2308) AND (inactive <> 1) AND (Contractor = 'DC')
  5.  
  6.  
thanks!
Dec 2 '09 #1

✓ answered by maxamis4

I found it thank you all for looking into this. Here is the what I found. The alias unlike oracle can not be referenced in the where clause. So to perform the calculation you must reference the table.[field]name followed by the formula. See below for example:

Expand|Select|Wrap|Line Numbers
  1. SELECT     last_name, SUBSTRING(alternate_identifier, 5, 2) AS Contractor
  2. FROM         ca_contact
  3. WHERE     (SUBSTRING(alternate_identifier, 5, 2) = 'DC')
  4.  

1 29595
maxamis4
295 Expert 100+
I found it thank you all for looking into this. Here is the what I found. The alias unlike oracle can not be referenced in the where clause. So to perform the calculation you must reference the table.[field]name followed by the formula. See below for example:

Expand|Select|Wrap|Line Numbers
  1. SELECT     last_name, SUBSTRING(alternate_identifier, 5, 2) AS Contractor
  2. FROM         ca_contact
  3. WHERE     (SUBSTRING(alternate_identifier, 5, 2) = 'DC')
  4.  
Dec 2 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: steve | last post by:
To gain performance, do I need to index ALL the fields in the where clause. Say we have a query like: select stuff from table where field1=.. and field2=... If field1 selection substantially...
14
by: joshsackett | last post by:
I have a WHERE clause that could be an "=" or a "LIKE" depending upon if the passed variable is populated or not. I would like to know the best way to write the WHERE clause to make it dynamically...
0
by: jobs | last post by:
I have a gridview that times when selecting from specific table when I try to when I add a where clause. Even when I'm only seleting Top 1 which comes right back at the command line. I test the...
2
by: Jim.Mueksch | last post by:
I am having a problem with using calculated values in a WHERE clause. My query is below. DB2 gives me this error message: Error: SQL0206N "APPRAISAL_LESS_PRICE" is not valid in the context where...
9
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
8
by: chrisdavis | last post by:
I'm trying to filter by query or put those values in a distinct query in a where clause in some sort of list that it goes through but NOT at the same time. Example: ROW1 ROW2 ROW3 ROW4 ,...
5
by: pwiegers | last post by:
Hi, I'm trying to use the result of a conditional statement in a where clause, but i'm getting 1)nowhere 2) desperate :-) The query is simple: -------- SELECT idUser,...
0
NeoPa
by: NeoPa | last post by:
Intention : To prepare a WHERE clause for multiple field selection, but to ignore any fields where the selection criteria are not set. ONLY WORKS WITH TEXT FIELD SELECTIONS. Scenario : You have...
6
by: Plissskin | last post by:
I need to create an "ad-hoc" filtering page in a web app we are building. The page would display a number of drop down lists, text boxes, and radio lists and allow the user to select (enter) some...
12
by: =?ISO-8859-1?Q?Ren=E9?= | last post by:
Hi, is there a rule of thumb what is better/faster/more performant in SQL Server 2005? a) SELECT * FROM A INNER JOIN B ON B.ID = A.ID AND B.Cond1 = 1 AND B.Cond2 = 2 b) SELECT * FROM A INNER...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.