query problem
-
hi I am trying to run this query
select Name from data where id='67' and file like '[pdfrtfdoc]%'
and it didn't give any data. well if my query is either
select Name from data where file like '[pdfrtfdoc]%'
or
select Name from data where id='67'
it runs. and also in the database it has record having id = 67 and file = *.pdf file. Need quick help.
suchita
-
hi I am trying to run this query
select Name from data where id='67' and file like '[pdfrtfdoc]%'
and it didn't give any data. well if my query is either
select Name from data where file like '[pdfrtfdoc]%'
or
select Name from data where id='67'
it runs. and also in the database it has record having id = 67 and file = *.pdf file. Need quick help.
suchita
Try this
where file in ('%pdf', '%rtf', '%doc')
:)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
Try this
where file in ('%pdf', '%rtf', '%doc')
:)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
Sorry that wasn't my question. I have two conditions one is id check and another is file check. If i put one of those conditions, it runs but if i put two conditions , then its not running.
suchita
If by "not running" you mean that no rows are returned, then that means that the rows returned from running the id check are different than the rows returned from running with the file check. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
hi I am trying to run this query
select Name from data where id='67' and file like '[pdfrtfdoc]%'
and it didn't give any data. well if my query is either
select Name from data where file like '[pdfrtfdoc]%'
or
select Name from data where id='67'
it runs. and also in the database it has record having id = 67 and file = *.pdf file. Need quick help.
suchita
why is 67 in quotes? ID fields normally are numeric, for maximum performance, and numeric literals don't take quotes. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
why is 67 in quotes? ID fields normally are numeric, for maximum performance, and numeric literals don't take quotes. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
no i tried both. actually is it possible to have sql conditions where there is LIKE condtion and other normal condition in the same statement. I can't find that example either. something like
select Name from data where id=67 and file like '[pdfrtfdoc]%'
or
select Name from Grapp1L where Name='suchita' and file like '[pdfrtfdoc]%'
the above both statements didn't run though i have data in both fields on the same row. when i run with only one condition, it runs. I have never tried LIKE condition with any other conditions. well I am familiar with multiple conditions though.
suchita
-
hi I am trying to run this query
select Name from data where id='67' and file like '[pdfrtfdoc]%'
and it didn't give any data. well if my query is either
select Name from data where file like '[pdfrtfdoc]%'
or
select Name from data where id='67'
it runs. and also in the database it has record having id = 67 and file = *.pdf file. Need quick help.
suchita
Since you have AND between the conditions both conditions must be true on the same row. So if you don't get any results with those two conditions but you do get results when using the conditions separately, you don't have a row in the table that satisfies both conditions at the same time. Also when you use LIKE operator like that, you select all rows that start with letters P, D, F, R, T, F (again), D(again), O or C. For example if the field file contains a value 'test.abc', this will satisfy the condition since it start with the letter T. Is this what you really want?
The need to optimize rises from a bad design.My articles[^]
-
no i tried both. actually is it possible to have sql conditions where there is LIKE condtion and other normal condition in the same statement. I can't find that example either. something like
select Name from data where id=67 and file like '[pdfrtfdoc]%'
or
select Name from Grapp1L where Name='suchita' and file like '[pdfrtfdoc]%'
the above both statements didn't run though i have data in both fields on the same row. when i run with only one condition, it runs. I have never tried LIKE condition with any other conditions. well I am familiar with multiple conditions though.
suchita
SayamiSuchi wrote:
no i tried both
only string literals need quotes. numeric literals don't.
SayamiSuchi wrote:
is it possible to ...
yes, of course. add a record that has id=67 and file="pqr", then try
select Name from data where id=67 and file like 'p%'
:)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.