tsql

How to find out what is represented by the intermediate value used in SQL Server execution plan

旧巷老猫 提交于 2021-01-21 09:32:31
问题 I'm learning how to read the actual execution plan in SQL Server. I have noticed that SQL Server tends to represent intermediate value used in the physical query plan as e.g. expr1006 , expr1007 etc. (i.e. expr followed by a number). Here is a screenshot. Notice near the bottom, the expressions expr1006, expr1008, expr1009 listed in the section output list . It it possible to find out what they really represent? 回答1: Right click the compute scalar and choose "properties". Look in the "Defined

How to find out what is represented by the intermediate value used in SQL Server execution plan

霸气de小男生 提交于 2021-01-21 09:32:06
问题 I'm learning how to read the actual execution plan in SQL Server. I have noticed that SQL Server tends to represent intermediate value used in the physical query plan as e.g. expr1006 , expr1007 etc. (i.e. expr followed by a number). Here is a screenshot. Notice near the bottom, the expressions expr1006, expr1008, expr1009 listed in the section output list . It it possible to find out what they really represent? 回答1: Right click the compute scalar and choose "properties". Look in the "Defined

Creating SQL table using dynamic variable name

▼魔方 西西 提交于 2021-01-20 18:09:43
问题 I want to create backup SQL tables using variable names. something along the lines of DECLARE @SQLTable Varchar(20) SET @SQLTable = 'SomeTableName' + ' ' + '20100526' SELECT * INTO quotename(@SQLTable) FROM SomeTableName but i'm getting Incorrect syntax near '@SQLTable'. It's just part of a small script for maintence so i don't have to worry about injections. 回答1: DECLARE @MyTableName nvarchar(20); DECLARE @DynamicSQL nvarchar(1000); SET @MyTableName = "FooTable"; SET @DynamicSQL = N'SELECT *

Creating SQL table using dynamic variable name

早过忘川 提交于 2021-01-20 18:08:23
问题 I want to create backup SQL tables using variable names. something along the lines of DECLARE @SQLTable Varchar(20) SET @SQLTable = 'SomeTableName' + ' ' + '20100526' SELECT * INTO quotename(@SQLTable) FROM SomeTableName but i'm getting Incorrect syntax near '@SQLTable'. It's just part of a small script for maintence so i don't have to worry about injections. 回答1: DECLARE @MyTableName nvarchar(20); DECLARE @DynamicSQL nvarchar(1000); SET @MyTableName = "FooTable"; SET @DynamicSQL = N'SELECT *

T-SQL Return All Combinations of a Table

痞子三分冷 提交于 2021-01-07 06:31:08
问题 In a different question, I asked about all possible 3-way combinations of a table, assuming that there are 3 articles. In this question, I would like to further extend the problem to return all n-way combinations of a table with n distinct articles. One article can have multiple suppliers. My goal is to have groups of combinations with each group having each article. Below is a sample table but keep in mind that there could be more than those 3 articles. +---------+----------+ | Article |

How to create pivot using sql

泪湿孤枕 提交于 2021-01-07 02:41:58
问题 I am new to SQL, I have a table like this. Below is the query : select gc.GC_Name, dt.GC_SectorType, dt.ageing, sum(cast(dt.[Brokerage Debtors] as numeric)) as Brokerage_Amt, dt.divisionalofficename from [AR].[Fact_Brokerage_Debt] dt inner join AUM.DIM_BUSINESS_TYPE BT on BT.Business_Type_WId_PK = dt.BusinessType_WID inner join aum.Dim_GroupCompany gc on dt.insurer_Wid = gc.GC_WID where bt.Business_Type_Wid in (4, 8, 10) and dt.ageing <> '<30' and cast(dt.[Brokerage Debtors] as numeric) > 0

Tracking a continuous instance of absence SQL

懵懂的女人 提交于 2021-01-07 02:41:15
问题 I have a table called sickness which is a record of when an employee is off work sick. It looks like this: Date_Sick Employee_Number ---------- ---------------- 2020-06-08 001 2020-06-10 001 2020-06-11 001 2020-06-12 001 2020-06-08 002 2020-06-09 002 What I'm trying to do is add a new column with a unique ID to identify a unique instance of absence. A unique instance of absence is one that runs in consecutive weekdays with no breaks. Hence my output table should look like this: Date_Sick

How to create pivot using sql

守給你的承諾、 提交于 2021-01-07 02:40:53
问题 I am new to SQL, I have a table like this. Below is the query : select gc.GC_Name, dt.GC_SectorType, dt.ageing, sum(cast(dt.[Brokerage Debtors] as numeric)) as Brokerage_Amt, dt.divisionalofficename from [AR].[Fact_Brokerage_Debt] dt inner join AUM.DIM_BUSINESS_TYPE BT on BT.Business_Type_WId_PK = dt.BusinessType_WID inner join aum.Dim_GroupCompany gc on dt.insurer_Wid = gc.GC_WID where bt.Business_Type_Wid in (4, 8, 10) and dt.ageing <> '<30' and cast(dt.[Brokerage Debtors] as numeric) > 0

Create a column to calculate the portion of balance for every shipment according to FIFO

此生再无相见时 提交于 2021-01-05 12:36:14
问题 I have a query to get Stock-items with it's Balance and Its receiving Transactions cods with its quantity Ordered By date, And i Want to create a column which has only the proportion Balance of every RS Code according to First in First Out Principle. As An Example in the attached sample we have StockItemId = (2222,2262,2263). and the expected result will be AS: As in Pic the Balance of every row in RS_Portion is depending on the Quantity of the Code and the sum of RS_Portion of every item

Is there any way to generate Alphabetic Sequence with Current Year In SQL

拥有回忆 提交于 2021-01-05 08:58:23
问题 How can we write a SQL function which can generate 'Sequence_Code' like AA,AB,AC....AZ. BA,BB,BC.... with the combination of last two digit of 'Current_Year' for each 'ID'. Order by 'Record_Date' For instance: If Current_Year of First row is is 2019, then Sequence_Code should be 19AA. My table is LoadData Sequence_Code ID Current_Year Record_Date NULL 310001 2019 2019-01-01 NULL 310002 2018 2018-02-22 NULL 310003 2020 2020-02-20 NULL 310004 2020 2020-02-10 Expected Output is: Sequence_Code ID