Showing posts with label shown. Show all posts
Showing posts with label shown. Show all posts

Thursday, March 22, 2012

ERROR in Where Cluase

Hello EveryBody,

I have a little problem in Sql Statement .. When I am adding a Where condtion to my sql statement ..I got an error shown in the pic blew :

I am waiting for your solution

Best regards,

It means that you have an error in your WHERE clause.Big Smile

What is the complete SELECT statement?

Don

|||

Good eveningdonkielySmile,

This is my SQL Statement:

SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued
FROM Products
WHERE CategoryID= @.CategoryID

and this is the erro shown in pic :-

Thank you for your concern

|||

Ah. I'm glad you sent the image. There cannot be a space between the @. and the CategoryID on the right side of the = sign.

Don

|||

Sad

Unfortunately, I was trying with no space ..but the same error happen >>

Shown in pic blew:-

Thanks Don

|||

ban:

This is my SQL Statement:

SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued
FROM Products
WHERE CategoryID= @.CategoryID

When I copy and paste that into Query Analyzer and run it against the Northwind database I receive no error. Are you sure that is your exact SQL statement?

|||

Dear tmorton,

yes , I am .It is the exact SQL Statemet .

but I am thinking maybe there is missing file on my program or somthing wrong with my keyboard.

I do not konw ,but this is not the first time that error happen to me ,every time I use WHERE Cluase .

I hop to find the solution for it .

anyway thanks to trying help meSmile

|||

Just a silly question, and don't kill me if it sounds really stupid to ask this please!

You are using SQL Server with the default sql server provider, yes?

|||

shadosIndifferent

OoOoOOOOOh God I am just a beginner programmer in ASP.NET ... I am so confuse

I did not get it your Q , but I am using a Microsoft Visual Studio .Net 2005 (Full Edition)

This version include Microsoft SQL Server 2005

Note : I can run SQL Statement with this program but I can not use WHERE Clause when it is taking a parameter

I appreciateyour help

|||

Okie, that answer my question, you are. All good then, I really don't get what the issue is. I was asking, because different databases have issues with SQL statements like the one you're writting (with parameters in the where clause), so I thought... But thats not the problem, so back to the drawining board >.<

|||

shados,

so back to the drawining boardTongue Tied

What do you mean by that ?

|||I just meant that my idea was wrong :)|||

Hellow againBig Smile,

I find the solution for my problem>>>shown in pic blew :-

Not: I am using Microsoft Acess DataBase.

Speical Thanks to >>donkiely ,tmorton,shados

for more info:-

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=874535&SiteID=1&mode=1

Have a nice day!

|||

ban:

I find the solution for my problem

That's great!!

ban:

Not: I am using Microsoft Acess DataBase.

This is the SQL Server forum. Next time please post in the Access forum. You would have had an answer days agoWink

|||

Gah, thats why I asked if you were using SQL Server :) In databases like MS Access, PervasiveSQL, a lot of databases accessed through ODBC, etc, you have to use the ? placeholder instead of @.variablename...

Indeed, since this is a SQL Server forum, we all assumed you were using SQL Server, hahahaha. Ahh well, glad you found your problem.

sql

Wednesday, March 7, 2012

Error in GroupBy

I have the query shown below which throws an error that "JudgeName" is an
invalid column name? Is using an alias not allowed here?
Wayne
================= code ==============
SELECT (Names.LastName + ', ' + Names.FirstName) As JudgeName
FROM JudgeEvals
Inner Join Judges On Judges.JudgeID = JudgeEvals.JudgeID
INNER JOIN Names ON Names.NameID=Judges.NameID
Group By JudgeName, CaptionSQL BASIC RULE: YOU CAN'T USE ALIAS IN GROUP BY
Method 1:
SELECT (Names.LastName + ',' + Names.FirstName) As JudgeName
FROM JudgeEvals
Inner Join Judges On Judges.JudgeID = JudgeEvals.JudgeID
INNER JOIN Names ON Names.NameID=Judges.NameID
Group By (Names.LastName + ',' + Names.FirstName), Caption
Method 2
SELECT a.JudgeName from
(SELECT (Names.LastName + ',' + Names.FirstName) As JudgeName
FROM JudgeEvals
Inner Join Judges On Judges.JudgeID = JudgeEvals.JudgeID
INNER JOIN Names ON Names.NameID=Judges.NameID
Group By Caption ) a GROUP BY a.JudgeName
Regards
R.D
"Wayne Wengert" wrote:

> I have the query shown below which throws an error that "JudgeName" is an
> invalid column name? Is using an alias not allowed here?
> Wayne
> ================= code ==============
> SELECT (Names.LastName + ', ' + Names.FirstName) As JudgeName
> FROM JudgeEvals
> Inner Join Judges On Judges.JudgeID = JudgeEvals.JudgeID
> INNER JOIN Names ON Names.NameID=Judges.NameID
> Group By JudgeName, Caption
>
>|||Wayne,
Unfortunately not. You can use the expression that makes up JudgeName. For
example,
SELECT (Names.LastName + ', ' + Names.FirstName) As JudgeName
FROM JudgeEvals
Inner Join Judges On Judges.JudgeID = JudgeEvals.JudgeID
INNER JOIN Names ON Names.NameID=Judges.NameID
Group By (Names.LastName + ', ' + Names.FirstName), Caption
- or -
SELECT (Names.LastName + ', ' + Names.FirstName) As JudgeName
FROM JudgeEvals
Inner Join Judges On Judges.JudgeID = JudgeEvals.JudgeID
INNER JOIN Names ON Names.NameID=Judges.NameID
Group By Names.LastName, Names.FirstName, Caption
Hope this helps,
Yosh
"Wayne Wengert" <wayneSKIPSPAM@.wengert.org> wrote in message
news:ugo4kVbxFHA.3644@.TK2MSFTNGP11.phx.gbl...
>I have the query shown below which throws an error that "JudgeName" is an
>invalid column name? Is using an alias not allowed here?
> Wayne
> ================= code ==============
> SELECT (Names.LastName + ', ' + Names.FirstName) As JudgeName
> FROM JudgeEvals
> Inner Join Judges On Judges.JudgeID = JudgeEvals.JudgeID
> INNER JOIN Names ON Names.NameID=Judges.NameID
> Group By JudgeName, Caption
>|||Locally, the GROUP BY is performed before the SELECT list, hence you cannot
group by a column alias.
Either repeat the expression in GROUP BY or use a derived table.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Wayne Wengert" <wayneSKIPSPAM@.wengert.org> wrote in message
news:ugo4kVbxFHA.3644@.TK2MSFTNGP11.phx.gbl...
>I have the query shown below which throws an error that "JudgeName" is an i
nvalid column name? Is
>using an alias not allowed here?
> Wayne
> ================= code ==============
> SELECT (Names.LastName + ', ' + Names.FirstName) As JudgeName
> FROM JudgeEvals
> Inner Join Judges On Judges.JudgeID = JudgeEvals.JudgeID
> INNER JOIN Names ON Names.NameID=Judges.NameID
> Group By JudgeName, Caption
>|||...
GROUP BY LastName, FirstName, Caption
David Portas
SQL Server MVP
--