Skip to content

Tag: tsql

T-SQL Equivalent of regular expression ‘b’

I’m in the process of converting a CLR function that utilizes regex to a SQL function. I know that SQL Server does not fully support regex, but i just need one case to work which is a word search. Search Field Value: {“Id”:1234, “Title”: “The quick brown”} Regex Patte…

Identity column as part of primary key

Suppose, I have a composite primary key that consists of 3 columns: [ShardKey], [SiteId] and [ServiceId]. Column [ServiceId] is an identity column and should start from 1 for a new combination of [ShardKey] and [SiteId], but SQL server fails – the column [ServiceId] never starts from 1, it just incremen…

How to get conditional SUM?

I am trying to get a conditional sum based on another column. For example, suppose I have this dataset: If there is a type of 1 then I only want that data for that data, else if there is only 0 then I want that data for that date. So for 12/16/2019 I would want the value 0. For 12/23/2019