Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 12th, 2008, 9:28 PM   #1
Logical1
Programmer
 
Logical1's Avatar
 
Join Date: Apr 2008
Posts: 43
Rep Power: 0 Logical1 is on a distinguished road
Question Sql Select

Hello

How do you querry and find records where specific characters are present in the string in a specific column.
I did not find a better place to post this question so here it is:
I have a column (FirstColumn) in my table with string values such as:
D2-L4-X1
D3-L4-X4
D9-L8-X9
SELECT * FROM tblListing WHERE FirstColumn = 'L4'
would not work. I tried LIKE that did not work either.
How would you do this querry?
Thanks a million in advance.
__________________
^c^
Logical1 is offline   Reply With Quote
Old Apr 12th, 2008, 10:23 PM   #2
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 498
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Sql Select

Did you try this: here

WHERE substring(FirstColumn,0,2) = 'L4'

or this depending on the implenmentation of SQL

WHERE substr(FirstColumn,0,2) = 'L4'
__________________
I Like Ike. Vote for Dwight Eisenhower this November.
--This message brought to you by the the Procrastinators Club Of America.
Ancient Dragon is offline   Reply With Quote
Old Apr 13th, 2008, 2:41 AM   #3
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 747
Rep Power: 3 Jimbo is on a distinguished road
Re: Sql Select

did you try something like SELECT * FROM tlbListing WHERE FirstColumn LIKE '%F4%'?
__________________
<insert disclaimer here>
<insert shameless plug for Visual Studio here>
Jimbo is offline   Reply With Quote
Old Apr 13th, 2008, 9:54 AM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Re: Sql Select

Wouldn't you be better off here with two tables? tblListing can link to another table which contains the same ID and multiple FirstColumns.
tblListing:
ID | RandomColumn | OtherColumn
---+--------------+------------
 1 |           46 |         910
 2 |         9295 |          11
 3 |            7 |         125

tblFirstColumn:
ID | FirstColumnPart
---+----------------
 1 | D2
 1 | L4
 1 | X1
 2 | D3
 2 | L4
 2 | X4
 3 | D9
 3 | L8
 3 | X9

Then you can do this:
SELECT tblListing.* FROM tblListing, tblFirstColumn WHERE tblListing.ID = tblFirstColumn.ID AND tblFirstColumn.FirstColumnPart = 'L4'
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 13th, 2008, 2:40 PM   #5
Logical1
Programmer
 
Logical1's Avatar
 
Join Date: Apr 2008
Posts: 43
Rep Power: 0 Logical1 is on a distinguished road
Thank you guys

Thank you guys I tried all your suggestions and each one worked.
Coffee shuld be on me!
__________________
^c^
Logical1 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Non distinct in MySQL davil PHP 12 Dec 6th, 2007 5:48 AM
SQL: Rewrite a complex join without #temp tables? jonyzz Other Scripting Languages 1 Sep 5th, 2007 10:51 AM
Detach an in-use database via code (SQL Server 2000) sma_soft C# 1 Aug 14th, 2007 2:22 PM
reloading html select boxs...is there a better way? MegaArcon Python 13 May 26th, 2006 3:06 AM
sockets, problem with select() Wizard1988 C++ 0 Jan 15th, 2006 4:09 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC