Tuesday, March 20, 2012

Queries and wildcards

I am trying to write a query with a wildcard as part of it. the table that I
am looking at is mostly text (they are smdr logs from my phone system) I
currently use access to write the queries connected to SQL server. in the
example below I need to put 1150 and 1152 for each of the t10xx numbers. I
would like to use a wildcard for the called_party but it does not work I hav
e
tried *,#, and a few others but no success. any ideas would be helpful.
SELECT date, start_time, calling_party, called_party, rx_calls
FROM dbo.[All Phone Logs]
WHERE (calling_party = N't1050') AND (called_party = N'1150') OR
(calling_party = N't1051') AND (called_party =
N'1150') OR
(calling_party = N't1052') AND (called_party =
N'1150') OR
(calling_party = N't1053') AND (called_party =
N'1150') OR
(calling_party = N't1054') AND (called_party =
N'1150') OR
(calling_party = N't1055') AND (called_party =
N'1150') OR
(calling_party = N't1056') AND (called_party =
N'1150') OR
(calling_party = N't1057') AND (called_party =
N'1150') OR
(calling_party = N't1058') AND (called_party =
N'1150') OR
(calling_party = N't1059') AND (called_party =
N'1150') OR
(calling_party = N't1060') AND (called_party =
N'1150') OR
(calling_party = N't1051') AND (called_party =
N'1152') OR
(calling_party = N't1052') AND (called_party =
N'1152') OR
(calling_party = N't1053') AND (called_party =
N'1152') OR
(calling_party = N't1054') AND (called_party =
N'1152') OR
(calling_party = N't1055') AND (called_party =
N'1152') OR
(calling_party = N't1056') AND (called_party =
N'1152') OR
(calling_party = N't1057') AND (called_party =
N'1152') OR
(calling_party = N't1058') AND (called_party =
N'1152') OR
(calling_party = N't1059') AND (called_party =
N'1152') OR
(calling_party = N't1060') AND (called_party = N'1152')The wild card characters supported in T-SQL are '%' and _ (underscore)
Roji. P. Thomas
Net Asset Management
http://toponewithties.blogspot.com
"Bill Farinella" <BillFarinella@.discussions.microsoft.com> wrote in message
news:A375B699-7ECF-4F4E-8DD2-F395D8B7C897@.microsoft.com...
>I am trying to write a query with a wildcard as part of it. the table that
>I
> am looking at is mostly text (they are smdr logs from my phone system) I
> currently use access to write the queries connected to SQL server. in the
> example below I need to put 1150 and 1152 for each of the t10xx numbers. I
> would like to use a wildcard for the called_party but it does not work I
> have
> tried *,#, and a few others but no success. any ideas would be helpful.
>
> SELECT date, start_time, calling_party, called_party, rx_calls
> FROM dbo.[All Phone Logs]
> WHERE (calling_party = N't1050') AND (called_party = N'1150') OR
> (calling_party = N't1051') AND (called_party =
> N'1150') OR
> (calling_party = N't1052') AND (called_party =
> N'1150') OR
> (calling_party = N't1053') AND (called_party =
> N'1150') OR
> (calling_party = N't1054') AND (called_party =
> N'1150') OR
> (calling_party = N't1055') AND (called_party =
> N'1150') OR
> (calling_party = N't1056') AND (called_party =
> N'1150') OR
> (calling_party = N't1057') AND (called_party =
> N'1150') OR
> (calling_party = N't1058') AND (called_party =
> N'1150') OR
> (calling_party = N't1059') AND (called_party =
> N'1150') OR
> (calling_party = N't1060') AND (called_party =
> N'1150') OR
> (calling_party = N't1051') AND (called_party =
> N'1152') OR
> (calling_party = N't1052') AND (called_party =
> N'1152') OR
> (calling_party = N't1053') AND (called_party =
> N'1152') OR
> (calling_party = N't1054') AND (called_party =
> N'1152') OR
> (calling_party = N't1055') AND (called_party =
> N'1152') OR
> (calling_party = N't1056') AND (called_party =
> N'1152') OR
> (calling_party = N't1057') AND (called_party =
> N'1152') OR
> (calling_party = N't1058') AND (called_party =
> N'1152') OR
> (calling_party = N't1059') AND (called_party =
> N'1152') OR
> (calling_party = N't1060') AND (called_party =
> N'1152')
>|||On Wed, 23 Nov 2005 07:30:11 -0800, Bill Farinella wrote:

>I am trying to write a query with a wildcard as part of it. the table that
I
>am looking at is mostly text (they are smdr logs from my phone system) I
>currently use access to write the queries connected to SQL server. in the
>example below I need to put 1150 and 1152 for each of the t10xx numbers. I
>would like to use a wildcard for the called_party but it does not work I ha
ve
>tried *,#, and a few others but no success. any ideas would be helpful.
(snip)
Hi Bill,
In this case, you might want to use IN instead of wildcards:
SELECT date, start_time, calling_party, called_party, rx_calls
FROM dbo.[All Phone Logs]
WHERE calling_party IN (N't1050', N't1051', ..., N't1060')
AND called_part IN (N'1150', N'1152')
Note: the ellipsis in the query above should be substituted by the full
list of valued you want to search for in calling_party.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Wow, Thanks That worked great!! I wish I posted this sooner now. It could
have saved me days worth of work.
Thanks again,
Bill
"Hugo Kornelis" wrote:

> On Wed, 23 Nov 2005 07:30:11 -0800, Bill Farinella wrote:
>
> (snip)
> Hi Bill,
> In this case, you might want to use IN instead of wildcards:
> SELECT date, start_time, calling_party, called_party, rx_calls
> FROM dbo.[All Phone Logs]
> WHERE calling_party IN (N't1050', N't1051', ..., N't1060')
> AND called_part IN (N'1150', N'1152')
> Note: the ellipsis in the query above should be substituted by the full
> list of valued you want to search for in calling_party.
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)
>

No comments:

Post a Comment