tsql

SQL Server - all possible combinations of Bit columns

谁说胖子不能爱 提交于 2021-02-11 13:32:49
问题 I have an empty table with 7 BIT columns (A, B, C, D, E, F, and G). I am looking to populate this table with rows representing all possible combinations of these columns. Ideally there would be no rows containing duplicates of the exact same combinations. Although I am showing 7 columns here, the number of columns could be greater, so the solution should be scalable. A snippet of the table after being populated would look similar to below: Ideally this would be based on an INSERT statement,

SQL Query with Cursor optimization

最后都变了- 提交于 2021-02-11 06:52:28
问题 I have a query where I iterate through a table -> for each entry I iterate through another table and then compute some results. I use a cursor for iterating through the table. This query takes ages to complete. Always more than 3 minutes. If I do something similar in C# where the tables are arrays or dictionaries it doesn't even take a second. What am I doing wrong and how can I improve the efficiency? DELETE FROM [QueryScores] GO INSERT INTO [QueryScores] (Id) SELECT Id FROM [Documents]

Split A Single Field Value Into Multiple Fixed-Length Column Values in T-SQL

送分小仙女□ 提交于 2021-02-11 06:06:19
问题 I've looked at about 15 different answers on SO but haven't found this exact situation yet. I'm doing a custom data export and need to export to a data file that will be imported into an older system that needs the data in a specific length/format. I have a "MEMO" column that can have a large amount of text in it. I need to select that value and split it into multiple columns with a FIXED length of 75 chars. For instance, if I have a row with a message that is 185 chars, I need to split that

Split A Single Field Value Into Multiple Fixed-Length Column Values in T-SQL

这一生的挚爱 提交于 2021-02-11 06:05:54
问题 I've looked at about 15 different answers on SO but haven't found this exact situation yet. I'm doing a custom data export and need to export to a data file that will be imported into an older system that needs the data in a specific length/format. I have a "MEMO" column that can have a large amount of text in it. I need to select that value and split it into multiple columns with a FIXED length of 75 chars. For instance, if I have a row with a message that is 185 chars, I need to split that

Split A Single Field Value Into Multiple Fixed-Length Column Values in T-SQL

纵然是瞬间 提交于 2021-02-11 06:03:43
问题 I've looked at about 15 different answers on SO but haven't found this exact situation yet. I'm doing a custom data export and need to export to a data file that will be imported into an older system that needs the data in a specific length/format. I have a "MEMO" column that can have a large amount of text in it. I need to select that value and split it into multiple columns with a FIXED length of 75 chars. For instance, if I have a row with a message that is 185 chars, I need to split that

SQL Server(T-sql) Update table from botom to top [closed]

旧城冷巷雨未停 提交于 2021-02-11 04:53:30
问题 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 4 years ago . Improve this question im trying to update table temp(F4) result from bottom to top. Is it while-loop every row and update can be order by? Thanks! 回答1: Assuming ROW is a positive integer then you can use (demo) WITH T1 AS ( SELECT *, MIN(CASE WHEN F4 <> 0 THEN CONCAT(FORMAT([ROW],'D10'),[F4]) END)

How to generate table name by datetime?

笑着哭i 提交于 2021-02-11 00:32:14
问题 I realize this is syntactically bad but I figure it somewhat explains what I'm trying to do. Essentially, I have a batch job that is going to run each morning on a small table and as a part of the spec I need to create a backup prior to each load that can be accessed by a report. What I have so far is: select * into report_temp.MSK_Traffic_Backup_ + getdate() from property.door_traffic How can I make this function or should I consider doing this a better way? 回答1: DECLARE @d CHAR(10) =

How to generate table name by datetime?

↘锁芯ラ 提交于 2021-02-11 00:31:23
问题 I realize this is syntactically bad but I figure it somewhat explains what I'm trying to do. Essentially, I have a batch job that is going to run each morning on a small table and as a part of the spec I need to create a backup prior to each load that can be accessed by a report. What I have so far is: select * into report_temp.MSK_Traffic_Backup_ + getdate() from property.door_traffic How can I make this function or should I consider doing this a better way? 回答1: DECLARE @d CHAR(10) =

Cursor for spliting t-sql @xml variable on elements level

穿精又带淫゛_ 提交于 2021-02-10 23:45:42
问题 I need to define some cursor for spliting t-sql @xml variable on elements level into different @xml(s). for example: <root> <element id=10/> <element id=11/> <element id=12/> <element id=13/> </root> so that get the following values inside of tsql cursor: <root><element id=10/><element id=11/></root> then <root><element id=12/><element id=13/></root> and so on where n number of elements pro cursor loop. 回答1: Well, you can use the build-in functions for manipulating XML . For example, the

Cursor for spliting t-sql @xml variable on elements level

亡梦爱人 提交于 2021-02-10 23:43:29
问题 I need to define some cursor for spliting t-sql @xml variable on elements level into different @xml(s). for example: <root> <element id=10/> <element id=11/> <element id=12/> <element id=13/> </root> so that get the following values inside of tsql cursor: <root><element id=10/><element id=11/></root> then <root><element id=12/><element id=13/></root> and so on where n number of elements pro cursor loop. 回答1: Well, you can use the build-in functions for manipulating XML . For example, the