MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2012, 01:33 PM
robertoronderos robertoronderos is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 robertoronderos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 34 sec
Reputation Power: 0
Exclamation Using plus sign within a column name?

Hello I'm trying to work with a database that has a table with a column name like so:
A_B+

The problem is that every time I try to perform a query with it in any php document it returns a mysql error. I understand the + sign is a reserved word/symbol in the grammar but somehow there's an auto generated form using the same column name and it is able to work with it normally. I do not have access to that code so I can't see how do they get away with it.

If you have any clue on how should I write this column name so that it's recognized by the engine without throwing an error please let me know!

thanks in advanced.

Reply With Quote
  #2  
Old November 9th, 2012, 04:23 PM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,357 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 4 h 33 m 45 sec
Reputation Power: 4140
Code:
SELECT `A_B+`, ... -- use `backticks`
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old November 12th, 2012, 11:04 AM
robertoronderos robertoronderos is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 robertoronderos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 34 sec
Reputation Power: 0
Quote:
Originally Posted by r937
Code:
SELECT `A_B+`, ... -- use `backticks`


That didn't work ... Still receiving the same error, here's the exact query:

SELECT count(DISTINCT ID) AS Totals
FROM table1 a
WHERE a.x= 'Atlantic City' AND a.A_B+ = 'Yes' AND a.Date BETWEEN '2012-10-01' and '2012-11-08'

I tried:
SELECT count(DISTINCT ID) AS Totals
FROM table1 a
WHERE a.x= 'Atlantic City' AND `a.A_B+` = 'Yes' AND a.Date BETWEEN '2012-10-01' and '2012-11-08'

Which gives me an SQL error ( SQL error (1054): Unknown column `a.A_B+` in 'where clause')

I also tried:
SELECT count(DISTINCT ID) AS Totals
FROM table1 a
WHERE a.x= 'Atlantic City' AND a.`A_B+` = 'Yes' AND a.Date BETWEEN '2012-10-01' and '2012-11-08'

which returns 0 as result and 0 is not the correct count.

Reply With Quote
  #4  
Old November 12th, 2012, 11:19 AM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,357 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 4 h 33 m 45 sec
Reputation Power: 4140
Quote:
Originally Posted by robertoronderos
...which returns 0 as result and 0 is not the correct count.
well, at least you solved your error, right? the backticks worked

as for why the query returned 0 rows, that's gotta be a data problem

dump a few rows for us and we'll prove it actually did work

Reply With Quote
  #5  
Old November 12th, 2012, 11:22 AM
robertoronderos robertoronderos is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 robertoronderos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 34 sec
Reputation Power: 0
Quote:
Originally Posted by r937
well, at least you solved your error, right? the backticks worked

as for why the query returned 0 rows, that's gotta be a data problem

dump a few rows for us and we'll prove it actually did work


No I'm using the same query for other columns and it works just fine, and also if I change the column name to another thing ( on my local machine , not on the live server ) it works fine as well.

Reply With Quote
  #6  
Old November 12th, 2012, 11:24 AM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,357 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 4 h 33 m 45 sec
Reputation Power: 4140
so the column name affects the count? i don't think so, bro

like i said, dump a few rows for us

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Using plus sign within a column name?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap