May 12, 2014 at 9:46 am
Can someone tell me what this phrase is doing? Found it in some code I'm inheriting:
WHEN PATINDEX ('%[^0-9-]%', @Num) = 0
May 12, 2014 at 9:54 am
It's checking to see whether @Num has any non-numeric characters in it. Look up the PATINDEX topic in Books Online for more information.
John
May 12, 2014 at 9:55 am
SQLalchemy (5/12/2014)
Can someone tell me what this phrase is doing? Found it in some code I'm inheriting:WHEN PATINDEX ('%[^0-9-]%', @Num) = 0
It is a regular expression...or as close as t-sql can get. It will return 0 when any character in the string is not 0-9.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 12, 2014 at 11:08 am
It's testing to make sure that @Num contains only "0"-"9"s and/or "-"s.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply