tsql

create cte multiple times and drop cte [closed]

我怕爱的太早我们不能终老 提交于 2020-01-25 06:45:47
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago . I am using a cte in stored procedure. I have to use it multiple times ie populate cte for different ids how can I drop or remove current cte thanks ;WITH PAYOUT_CTE(REGNKEY, REGNTPE) AS ( SELECT REG_KEY, 'Parent' FROM ML_MSTR_REGN A (NOLOCK) WHERE A.COMP_NO = @COMP_NO AND A.REG_KEY = @CUR_KEY UNION

How do I put a condition in the select statement in T-SQL

邮差的信 提交于 2020-01-25 06:43:09
问题 A carer can provide support to two different service at the same Start time and End time this is called 1:2 Service type. The unique ID for this type of shift type are generated as the same unique ID for this type of service. I want to add 2 at the end of the unique ID for every second service. How do I find this? Bare in mind I am using this within the UNION with other 3 select statement. The first query above the Union is the one My query below: SELECT DISTINCT CASE WHEN SHIFT_CODE = '1:2

Select non duplicate values from rows that are less than a specified number of minutes apart

感情迁移 提交于 2020-01-25 06:25:29
问题 I have a huge table with the following format: DATETIME NUMBER -------------------------------------- 2009-03-31 16:05:52.000 2453651622 2009-03-31 16:16:12.000 30206080 2009-03-31 16:16:16.000 16890039 2009-03-31 16:16:28.000 2452039696 2009-03-31 16:16:33.000 140851934 2009-03-31 16:16:51.000 2453120306 2009-03-31 16:16:57.000 2453120306 ... 2009-04-01 21:15:24.000 2453651622 How can I select the rows that don't have duplicate numbers in the second column if they occur less than 15 minutes

Char returns the wrong value for 29 unicode characters - Need .NET cast / convert of nchar to char

六月ゝ 毕业季﹏ 提交于 2020-01-25 03:21:28
问题 Need a .NET cast / convert of the SQL nchar to char. More specifically cast of the nchar UNICODE to the char ASCII. Where this is complicated is SQL char uses the full byte. Not the pure ASCII of 128. The TSQL function ASCII returns 0-255. Ideally there would be a NormalizationForm of FormByte. It would not be an exact textual value - rather a close logical value or ?. And SQL would use the FormByte to cast from nchar to char. NormalizationForm Encode Decode did not work for me and I tried

Unpacking a binary string with TSQL

南楼画角 提交于 2020-01-25 02:22:06
问题 Good Day, I have a number of binary strings that were created by a C app with a struct. Imagine, if you will, the struct looks like this: struct { int foo; double bar; //Assume 8 bytes char[20] baz; } Each string is 4 + 8 + 20 = 32 bytes long. The structure of the string looks something like this: IIIIDDDDDDDDSSSSSSSSSSSSSSSSSSSS I need to unpack this string in a TSQL stored proc. The string is easy: baz = SUBSTRING(binarystring, 12, 20) The int also. And then convert to an integer with bit

How to use XQuery to simulate STRING_AGG() (grouped string concatenation)?

牧云@^-^@ 提交于 2020-01-25 00:17:08
问题 I have XML data which I need to convert to relational form. I use XQuery cause I don't know the number of address nodes. I'd like to get the whole address/adresses separeted by a comma. I guess I need to use LET clause but I'm still receiving an error. Here's my code: declare @xml as xml = '<root> <Row> <proceeding> <signatures>V GU 86/18</signatures> <signatures>V GUp 9/19</signatures> <signatures>V GUp 8/19</signatures> </proceeding> <entity> <info> <cleaned_name>Kate Smith</cleaned_name> <

SUBSTRING() and hex value

我是研究僧i 提交于 2020-01-24 23:42:46
问题 How does substring work on hexadecimal values? See this: PRINT SUBSTRING(0x6,1,1) PRINT SUBSTRING(0xF6,1,1) PRINT SUBSTRING(0xFF6,1,1) PRINT SUBSTRING(0xFFF6,1,1) ...outputs... 0x06 0xF6 0x0F 0xFF ...which currently looks as a complete nonsense to me. But it can somehow used in detecting which column is updated in trigger (see COLUMNS_UPDATED()). I tried: intermediately converted it to string and then substring it intermediately converted it to int, then string and then substring it searching

SQL Trigger on Update, Insert, Delete on non-specific row, column, or table

我怕爱的太早我们不能终老 提交于 2020-01-24 21:50:53
问题 I have several databases that are used by several applications (one of which is our own, the others we have no control over in what they do). Out software has to know when the database has last been changed. For reasons I won't get into to keep this short we decided that going with a new table per database that has a singular field: last_changed_on that has a GetDate() as a value. This way our own software can check when it was last changed and check it to the date it has stored for said

Export SQL Server database to XML Optimization

瘦欲@ 提交于 2020-01-24 21:01:25
问题 I have SQL Server database for articles. Articale table: CREATE TABLE [dbo].[T_Articale] ( [id] [int] IDENTITY(1,1) NOT NULL, [Title] [nvarchar](100) NULL, [Text] [nvarchar](max) NULL, [LocationID] [int] NULL, [TribeID] [int] NULL, [ArticaleText] [nvarchar](max) NULL, [ArticaleDate] [date] NULL, [SearchID] [int] NULL, [ClassificationID] [int] NULL, [CountryID] [int] NULL, [isLocal] [int] NULL, [Note] [nvarchar](150) NULL, CONSTRAINT [PK_T_Articale] PRIMARY KEY CLUSTERED ) Where ArticaleText

Export SQL Server database to XML Optimization

拜拜、爱过 提交于 2020-01-24 21:01:12
问题 I have SQL Server database for articles. Articale table: CREATE TABLE [dbo].[T_Articale] ( [id] [int] IDENTITY(1,1) NOT NULL, [Title] [nvarchar](100) NULL, [Text] [nvarchar](max) NULL, [LocationID] [int] NULL, [TribeID] [int] NULL, [ArticaleText] [nvarchar](max) NULL, [ArticaleDate] [date] NULL, [SearchID] [int] NULL, [ClassificationID] [int] NULL, [CountryID] [int] NULL, [isLocal] [int] NULL, [Note] [nvarchar](150) NULL, CONSTRAINT [PK_T_Articale] PRIMARY KEY CLUSTERED ) Where ArticaleText