Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


WildCard Expression


WildCard Expression

Author
Message
DB_Newbie2007
DB_Newbie2007
SSC Veteran
SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)

Group: General Forum Members
Points: 204 Visits: 1329
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! Smile

Argue for your limitations, and sure enough they're yours (Richard Bach, Illusions)
Adrian Nichols-360275
Adrian Nichols-360275
SSC Eights!
SSC Eights! (816 reputation)SSC Eights! (816 reputation)SSC Eights! (816 reputation)SSC Eights! (816 reputation)SSC Eights! (816 reputation)SSC Eights! (816 reputation)SSC Eights! (816 reputation)SSC Eights! (816 reputation)

Group: General Forum Members
Points: 816 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...
Wilfred van Dijk
Wilfred van Dijk
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1025 Visits: 1352
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
Madhivanan-208264
Madhivanan-208264
Old Hand
Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)

Group: General Forum Members
Points: 337 Visits: 476
I am not sure if this works

where ActualTime >0



Madhivanan

Failing to plan is Planning to fail
DB_Newbie2007
DB_Newbie2007
SSC Veteran
SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)

Group: General Forum Members
Points: 204 Visits: 1329
Thanks for the suggestions all! Smile

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).

BigGrin

Argue for your limitations, and sure enough they're yours (Richard Bach, Illusions)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search