tags:

views:

44

answers:

2

what is the syntax of sql query has intersection between 2 "where Like" condition

string command_get_pay = "select Credit 
                            from Update_Company_Credit 
                           where ( Update_Date LIKE '%" + 8 + "%'& Update_Date LIKE 18'%" + 8 + "%')";`

is this true I try it but I got exception in syntax

A: 

the & should be probably OR?

SQLMenace
+2  A: 

Do you mean:

SELECT
    Credit
FROM
    Update_Company_Credit
WHERE
    Update_Date LIKE '%" + 8 + "%'
    AND Update_Date LIKE 18'%" + 8 + "%'
;

Also, LIKE takes a string to use for search, but your second LIKE appears to be invalid... what is 18'%" + 8 + "%')"?

Edit: Oh, this is C#. Still makes no sense: how are you adding a string and an integer?

Thanatos
I think he wants probably OR, because a column can't be 2 values at the same time
SQLMenace
sorry 18'%" + 8 + "%')" is wrong it is only LIKE '%" + 8 + "%')"
salamonti
Well, he says "intersection", which is an `AND` kind of operation. A `LIKE '%blue%' AND LIKE '%green%'` can match rows, and is different from the same statement with `OR`. His statements seem to follow this pattern, so, ideally, he should clarify which is intended...
Thanatos
@salamonti: That's a little clearer, but if this is C#, how are you adding a string and an integer?
Thanatos
normal I tried 1 'Like' condition with integer and I didn't got exception and it worked because I search in datetime type
salamonti
thank you Thanatos your query is executed good thanks a lot
salamonti
+1: @salamonti - don't forget to vote up answers you think are worth it. Click the arrow above the number to the left of the answer.
OMG Ponies
ooh thank you I am sorry I didn't know this information so I make is as right answer I will repair it
salamonti