MSSQL - Checking if a string contains only digits
Example of checking if a string contains only digits: SELECT * FROM my_table WHERE user_name NOT LIKE '%[^0-9]%';
38 posts
Example of checking if a string contains only digits: SELECT * FROM my_table WHERE user_name NOT LIKE '%[^0-9]%';
Example of applying SPLIT_STRING for all rows in the set using one script. -- Creating a dataset for the example declare @tbl table(path varchar(max)); insert into @tbl select 'root_home_user' union select 'lib_var_simple' union select 'var_...
Example of returning a parameter when executing a dynamically created query. May be useful in cases where you need to return parameters for further processing in a script, for example, a procedure. We will use this for <b>sp_executesql</b>.
Добавление описания к полю в таблице EXEC sp_addextendedproperty @name = N\'MS_Description\', @value = N\'Описание поля\', @level0type = N\'SCHEMA\', @level0name = N\'CRM\', -- Вместо \'dbo\' ставим название своей схемы если отличается @lev…
Examples of getting the query text by session identifier DECLARE @sqltext VARBINARY(128) SELECT @sqltext = sql_handle FROM sys.sysprocesses WHERE spid = (YourSessionID) SELECT TEXT FROM sys.dm_exec_sql_text(@sqltext) GO SELECT TEXT FROM sy…
Example of selecting fields from a temporary table with all parameters. Can be used for regular tables as well. #tmp - your temporary table
--generate disable deactivation SELECT 'exec msdb..sp_update_job @job_name = ''+NAME+'', @enabled = 0' FROM msdb..sysjobs --generate enable activation SELECT 'exec msdb..sp_update_job @job_name = ''+NAME+'', @enabled = 1'
Stopping Database Mail exec msdb.dbo.sysmail_stop_sp Cleaning the history of undelivered messages -- If the number of records in the msdb.sysmail_allitems table is very large, -- then use the @sent_before parameter to limit the deleted records exec msdb.dbo.sysmail_delete_mailitems_sp @sent_status =
Converting DATE or DATETIME to INT (format YYYYMMDD) declare @dt datetime set @dt = '\09-22-2007 15:07:38.850\' select cast(convert(char(8),@dt,112) as int) Converting INT (format YYYYMMDD) to DATE declare @dti int = 20071022; select cast(@dti as datetime)
Example of date trimming to minutes and hours: declare @dt datetime set @dt = '09-22-2007 15:07:38.850' select dateadd(mi, datediff(mi, 0, @dt), 0) select dateadd(hour, datediff(hour, 0, @dt), 0)