Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

WildCard Expression Expand / Collapse
Author
Message
Posted Thursday, September 18, 2008 8:54 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 6:32 AM
Points: 186, Visits: 1,192
I was wondering if there is a wildcard version of the following IN statement:

select top 10 * from dbo.MyTable
where ActualTime NOT IN
('0','00','000','0000')

There is a field in this table, dbo.MyTable, ActualTime which is a char(4). Instead of a datetime value, this table is fed the actual time as a seperate field. I was hoping to get a query like below so I do not have to repeat every possible "0" scenario as I did above.

select top 10 * from dbo.MyTable
where ActualTime NOT IN
('0*')

Thanks! :)


Argue for your limitations, and sure enough they're yours (Richard Bach, Illusions)
Post #571839
Posted Thursday, September 18, 2008 9:06 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, August 4, 2009 10:02 AM
Points: 814, Visits: 915
It's not a wildcard expression but you could use something like:

WHERE REPLACE(actualTime, '0', '') <> ''

or
WHERE CAST(actualTime AS INT) <> 0

The replace would result in any actualTime string containing only zeros to be a zero-length string. Although I have no idea on the performance of either of these on mass.

You might wish to consider changing the column definition to an INT and the check for anything that is not zero. I'm sure the performance of that would be better than any fuction performed in a WHERE clause.




Ade

A Freudian Slip is when you say one thing and mean your mother.
For detail-enriched answers, ask detail-enriched questions...
Post #571853
Posted Friday, September 19, 2008 4:27 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, August 14, 2014 8:25 AM
Points: 929, Visits: 1,127
Or use something like

select top 10 * from dbo.MyTable
where ActualTime NOT like '0%'

but this construction is a performance killer.


Wilfred
The best things in life are the simple things
Post #572387
Posted Friday, September 19, 2008 7:55 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, May 23, 2014 5:59 AM
Points: 329, Visits: 470
I am not sure if this works

where ActualTime >0




Madhivanan

Failing to plan is Planning to fail
Post #572535
Posted Friday, September 19, 2008 8:35 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 6:32 AM
Points: 186, Visits: 1,192
Thanks for the suggestions all! :)

Doing a replace would not work, as any occurrences such as 0901 would become 9 1 (char data). But doing WHERE CAST(ActualTime AS INT) <> 0 will work.

Excluding any occurrences NOT like '0%' would skip 0901 (the char data is in military time).

The suggestion that works at the moment is the where ActualTime > '0000' (has to be 4 zeros to exlude 0, 00, 000 as well as 0000 - again, char data).

The downside is missing anything that midnight, which I never accounted for in my original post, but that is a problem for another day. Unfortunately midnight is 0000 and "no data" can also be represented by 0000, amoung other things (0,00,000 and blank).

:D


Argue for your limitations, and sure enough they're yours (Richard Bach, Illusions)
Post #572588
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse