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]%';
16 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>.
IN select * from Rating where ID_PLAYER in ( select ID_PLAYER from Players where PLAYER_STATUS = 'Active' ); EXISTS select * from Rating r where exists ( select 1 from Players p where p.ID_PLAYER = r.ID_PLAYER and p.PLAYER_STATUS = 'Acti…
Добавление описания к полю в таблице 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
Below is an example of correctly canceling a transaction with an error: update Params set Value=168 where Param = 'SessionHoursLimit' PRINT @@TRANCOUNT BEGIN TRY BEGIN TRAN PRINT @@TRANCOUNT update Params set Value=167 where Param = 'SessionHours…
Simple MERGE example for TSQL. The example assumes that we are working with two tables of the same structure (in real life, this condition is not necessary). The TargetTable and SourceTable tables consist of only two fields: Id - some identifier. Name - object name.
Recently came across a very useful resource for all developers working with databases, called Connection Strings. The resource is a collection of various connection strings to different databases using various providers and technologies. Very useful resource. Here is the link: <a href="[[B0]]" target="_blank" rel="noopener external">[[B1]]</a>. The resource is in English, but I assume it's not a problem for those who need it.