Check if a column contains text using SQL

Leaving database modeling issues aside. I think you can try SELECT * FROM STUDENTS WHERE ISNUMERIC(STUDENTID) = 0 But ISNUMERIC returns 1 for any value that seems numeric including things like -1.0e5 If you want to exclude digit-only studentids, try something like SELECT * FROM STUDENTS WHERE STUDENTID LIKE ‘%[^0-9]%’

Generate a resultset of incrementing dates in T-SQL

If your dates are no more than 2047 days apart: declare @dt datetime, @dtEnd datetime set @dt = getdate() set @dtEnd = dateadd(day, 100, @dt) select dateadd(day, number, @dt) from (select number from master.dbo.spt_values where [type] = ‘P’ ) n where dateadd(day, number, @dt) < @dtEnd I updated my answer after several requests to do … Read more

Splitting delimited values in a SQL column into multiple rows

If you are on SQL Server 2016+ You can use the new STRING_SPLIT function, which I’ve blogged about here, and Brent Ozar has blogged about here. SELECT s.[message-id], f.value FROM dbo.SourceData AS s CROSS APPLY STRING_SPLIT(s.[recipient-address], ‘;’) as f; If you are still on a version prior to SQL Server 2016 Create a split function. … Read more

How do I convert a number to a numeric, comma-separated formatted string?

The reason you aren’t finding easy examples for how to do this in T-SQL is that it is generally considered bad practice to implement formatting logic in SQL code. RDBMS’s simply are not designed for presentation. While it is possible to do some limited formatting, it is almost always better to let the application or … Read more