Wednesday, March 7, 2012

I need some help on my Sql string

Hi,

i have a sqlString to select records from database as below,


StrSql="Select Distinct ItemCode From StockOnHand Where " & _
"Description like @.Des"

this sql string works correctly, but i need to display those distinct ItemCode with their Description and Price, but i failed using the sql String at below...


StrSql="Select Distinct ItemCode, Description, Price From StockOnHand Where " & _
"Description like @.Des"

I know there is something wrong with my sql string.. but my SQL knowledge is onli at the basic level, can any1 pls help me on this...?

Thanks in advances
life's Ng::I know there is something wrong with my sql string..

Good, let's start VERY VERY VERY at the basics.

This:

::but i failed using the sql String at below...

will NOT get you help.

It did not "just fail", it gave you an error string DESCRIBING the error. Now, even while you may not understand this error string when you read it (and normally it is pretty self-explaining), WE may want to have a look at the EXACT error coming there.

So please, post the error you got, too.

Btw, using:

"Select DISTINCT" is about the best way to kill your peroformance anyhow. And - sorry - not really smart in the queries you give there. Unless, naturally, you want your database to be terribly slow.|||Without knowing the exact error, I can tell you that this is not correct:
"Description like @.Des"

try this instead:
"Description like '%@.Des%'"|||Hi, Sorry for my mistake to not descript my problem well and thanks for ur info bout "DISTINCT"

i dint receive any error with both of the SQL statements.

In my table, there is 10 columns ("Description", "ItemCode", "Prices".......)

the 2nd one return records which is not expected... few records selected with the same ItemCode, i onli want the distinct ItemCode displayed according to its description.

This page is created just for user to search&check on the ItemCode using their Description... I think i need to reconstruct my database design.

Best Regards
life's Ng

No comments:

Post a Comment