Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Directory Submission Service   I Sell Pagerank   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 07-14-2004, 07:53 AM   #1 (permalink)
Inactive
 
Join Date: 10-13-03
Location: Nova Scotia, Canada
Posts: 63
iTrader: 0 / 0%
Latest Blog:
None

Devil's Angel is liked by many
Send a message via ICQ to Devil's Angel Send a message via MSN to Devil's Angel
SQL Syntax for Like

Hey everyone!

This is probably a realy easy fix that I'm overlooking. I always mess up the syntax for SQL.

I'm trying to do a like on a date field.

On one page I have the user select a month which is in a querystring. The next page takes the string and changes it slightly so I can compare it to a date field in my database. My code:

Month = QueryString("Month")

If Month = "1" Then
Month = "1%"
End If

I make it change to 1% because to do a like you add % after so it looks for everything that starts with 1.

sql = "SELECT select bunch of fields including date of publication WHERE [News-Clippings-Information].[Date of Publication] LIKE 'Month' "

Now this doesn't output anything....the Month variable does output 1% if I just call <%=Month%>

If I use the same statement above but replace 'Month' with '1%' it works fine. So I tried just Month...error...I tried "Month"....error...I tried a whole bunch more...still error.

I'm sure it's just a small stupid syntax error...but if someone could point it out I would much appreciate it!
Devil's Angel is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 07-14-2004, 10:45 AM   #2 (permalink)
v7n Mentor
 
hatchet's Avatar
 
Join Date: 10-11-03
Posts: 1,137
iTrader: 0 / 0%
Latest Blog:
None

hatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nice
I'm assuming you're using a submission form or a string in the URL.. find.php?month=2
Right before you call your sql statement just concatenate the % sign on the end..
In php it would be
$month = $_GET[month].'%';
then in the select statement you would have
Publication] LIKE '$month'";
hatchet is offline  
Add Post to del.icio.us
Reply With Quote
Old 07-15-2004, 09:02 AM   #3 (permalink)
Inactive
 
Join Date: 02-23-04
Location: South UK
Posts: 60
iTrader: 0 / 0%
Latest Blog:
None

ILoveJackDaniels is liked by many
You aren't using the variable month. You're using the word Month.

[code:1:627fdafba4]sql = "SELECT select bunch of fields including date of publication WHERE [News-Clippings-Information].[Date of Publication] LIKE '" & Month & "' "[/code:1:627fdafba4]

You might want to be a bit careful of SQL injection too...

[code:1:627fdafba4]Month = replace(Month, "'", "''")[/code:1:627fdafba4]
ILoveJackDaniels is offline  
Add Post to del.icio.us
Reply With Quote
Old 07-16-2004, 06:53 AM   #4 (permalink)
Inactive
 
Join Date: 10-13-03
Location: Nova Scotia, Canada
Posts: 63
iTrader: 0 / 0%
Latest Blog:
None

Devil's Angel is liked by many
Send a message via ICQ to Devil's Angel Send a message via MSN to Devil's Angel
Quote:
Originally Posted by ILoveJackDaniels
[code:1:75776b7560]sql = "SELECT select bunch of fields including date of publication WHERE [News-Clippings-Information].[Date of Publication] LIKE '" & Month & "' "[/code:1:75776b7560]
Thanks! That worked perfectly!
Devil's Angel is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
htaccess syntax question insidedesign Web Hosting Forum 3 02-26-2007 01:04 PM
mySQL syntax problems TeKBuzz Coding Forum 5 03-07-2005 02:32 PM
MySQL syntax question downtroden Coding Forum 1 12-27-2004 01:16 AM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 08:45 PM.
© Copyright 2008 V7 Inc