Purpose: To compare two strings with a supplied operator and return true if the strings evaluate to true using the operator provided. This is useful for stored procs to use instead of dynamic sql. YAY! Allowing for the operator and value to be passed in as parms. So that the user on the front end can pick the comparison he wants to use against the field being searched. I based my idea for this function upon 2 excellent articles from Robert Marda :
http://www.sqlservercentral.com/columnists/rmarda/howdynamiccanstaticbe.asp
http://www.sqlservercentral.com/columnists/rmarda/howdynamicsqlcanbestatic2.asp
EX: SELECT dbo.fnStringCompare('test', default, 'test')
OR
SELECT * FROM TABLE WHERE dbo.fnStringCompare(TABLE.COLUMN, 'LIKE %VAL%', 'test') = 1
NOTE : Depending upon the collation of your sql server
text case may be important and affect the results
Returns (smallint) :
-1 : Null or empty string operator
-2 : Invalid operator type
1 : The expression was valid
0 : None of the above was true, and somehow got
past my checks, should never happen
A Normalization Primer
For most DBAs, normalization is an understood concept, a bread and butter bit of knowledge. However, it is not at all unusual to review a database design by a development group for an OLTP (OnLine Transaction Processing) environment and find that the schema chosen is anything but properly normalized. This article by Brian Kelley will give you the core knowledge to data model.
2003-01-13
18,597 reads