tsql

is there any way to get the list of the inbuilt function of the sql server?

旧街凉风 提交于 2020-02-28 09:51:49
问题 SELECT * FROM sysobjects WHERE xtype='p' above query will give us the list of all procedures in the database, in the same way how can I get the list of internal functions? 回答1: Try this SELECT name, definition, type_desc FROM sys.sql_modules m INNER JOIN sys.objects o ON m.object_id=o.object_id WHERE type_desc like '%function%' Or else: SELECT * FROM sys.all_objects where type in ('FN','AF','FS','FT','IF','TF') Here are the types: --AF = Aggregate function (CLR) --C = CHECK constraint --D =

is there any way to get the list of the inbuilt function of the sql server?

社会主义新天地 提交于 2020-02-28 09:49:00
问题 SELECT * FROM sysobjects WHERE xtype='p' above query will give us the list of all procedures in the database, in the same way how can I get the list of internal functions? 回答1: Try this SELECT name, definition, type_desc FROM sys.sql_modules m INNER JOIN sys.objects o ON m.object_id=o.object_id WHERE type_desc like '%function%' Or else: SELECT * FROM sys.all_objects where type in ('FN','AF','FS','FT','IF','TF') Here are the types: --AF = Aggregate function (CLR) --C = CHECK constraint --D =

Last time value changed from negative to positive

ぐ巨炮叔叔 提交于 2020-02-28 07:04:50
问题 How can you return the date by PersonID when the last time the Balance field went from a negative value to a positive value? In the sample data below, for PersonID 1 it happened for 8th July 2019, for PersonID 2 it happened for 8th August 2019. There can be multiple times the value changes from negative to positive but it should only reference the latest time it happens. Expected Output: I have the below sample data Create Table #temp ( PersonID int, ActionDate date, Balance money ) insert

Compare two tables and insert all records with added or removed status in 3rd table using SQL Server procedure

爱⌒轻易说出口 提交于 2020-02-26 04:04:12
问题 I have table A and table B . I have to compare this tables records and insert data to table C using SQL Server procedure in below format table A name A B C D E F G table B name A B Q C D F G table c should be like below. it has an extra field 'status' to mention record is added or removed. name status A B Q newly added C D E removed F G I know we can compare 2 tables and find added or removed records using EXCEPT and UNION operations. But in this case, I have to integrate that records with

How to generate a RNGCryptoServiceProvider-like number in TSQL

那年仲夏 提交于 2020-02-25 05:50:54
问题 Does anyone know of a way to generate a RNGCryptoServiceProvider-like random number in T-SQL without having to register any .NET Assemblies? 回答1: SELECT CHECKSUM(NEWID()) gives you a 32 signed integer based on GUIDs. You can use this as base: it's pretty much the best SQL way You can use it to seed RAND (because RAND is the same for all rows in a single select. SELECT RAND(CHECKSUM(NEWID())) A signed 64 bit integer: SELECT CAST(CHECKSUM(NEWID()) as bigint) * CAST(CHECKSUM(NEWID()) as bigint)

How to generate a RNGCryptoServiceProvider-like number in TSQL

▼魔方 西西 提交于 2020-02-25 05:50:19
问题 Does anyone know of a way to generate a RNGCryptoServiceProvider-like random number in T-SQL without having to register any .NET Assemblies? 回答1: SELECT CHECKSUM(NEWID()) gives you a 32 signed integer based on GUIDs. You can use this as base: it's pretty much the best SQL way You can use it to seed RAND (because RAND is the same for all rows in a single select. SELECT RAND(CHECKSUM(NEWID())) A signed 64 bit integer: SELECT CAST(CHECKSUM(NEWID()) as bigint) * CAST(CHECKSUM(NEWID()) as bigint)

Does SQL Server acquire locks even without an explicit transaction?

拟墨画扇 提交于 2020-02-24 09:22:11
问题 I was reading about MSSQL Locking for the first time, and it many places, the locking mechanism concepts depend on the existence of Transactions. I was wondering whether locking (in general) is possible without having any Transactions involved? 回答1: When no explicit transaction exists, each SQL statement is executed in an automatic (autocommit) transaction. Normal locking behavior will apply in that case and the locks released when the automatic transaction is completed as the statement

Join on data from XML in T-SQL

删除回忆录丶 提交于 2020-02-23 09:47:48
问题 I have the following XML message: DECLARE @XML AS XML SET @XML = '<Message> <Changes> <Deleted> <ROW id="1" name="Nicole" surname="Bartlett" city="denver" balance="779.4663" dateOfBirth="1991-12-11T14:05:42.830" maritalStatus="S" /> <ROW id="1" name="Nicole" surname="Bartlett" city="boston" balance="779.4663" dateOfBirth="1991-12-11T14:05:42.830" maritalStatus="S" /> </Deleted> <Inserted> <ROW id="1" name="Nicole" surname="Bartlett" city="denver" balance="779.4663" dateOfBirth="1991-12-11T14

SQL Server : cannot access temporary tables

本秂侑毒 提交于 2020-02-23 08:56:07
问题 How can I create a table-valued function from this query? I need to calculate time as result HH:MM between start and end job time This query work when I run it in SQL : DECLARE @USERID int; SET @USERID = 10 DECLARE @JOBStartDATE DATETIME; SET @JOBStartDATE = (SELECT StartJOBHoursDATE FROM JOBs WHERE ID=@USERID) DECLARE @StartTime DATETIME; DECLARE @JOBDateTime DATETIME; DECLARE @JOBEvent nvarchar(50); DECLARE @totalTime int; SET @totalTime = 0; SELECT ROW_NUMBER() OVER(ORDER BY JOBID) AS

MERGE INTO insertion order

白昼怎懂夜的黑 提交于 2020-02-21 11:47:28
问题 I have a statement that looks something like this: MERGE INTO someTable st USING ( SELECT id,field1,field2,etc FROM otherTable ) ot on st.field1=ot.field1 WHEN NOT MATCHED THEN INSERT (field1,field2,etc) VALUES (ot.field1,ot.field2,ot.etc) where otherTable has an autoincrementing id field. I would like the insertion into someTable to be in the same order as the id field of otherTable , such that the order of id s is preserved when the non-matching fields are inserted. A quick look at the docs