sql-server-2012

Calculating a running count & running total across customers with SQL

久未见 提交于 2020-08-22 17:51:17
问题 I have the following table (SQL Server 2012): DID - cust id GID - order id AMT - order amt Gf_Date - order date SC - order reversal amount I'm trying to calculate a running count of orders and a running total of sales by customer so that I can assign a flag to the point in time where a customer achieved cumulative sales of $1,000. As a first step, I've run this query: Select [DID] , [AMT] , [Gf_Date] , COUNT([GID]) OVER (PARTITION BY [DID] ORDER BY [Gf_Date]) [RunningGift_Count] , SUM([AMT])

Calculating a running count & running total across customers with SQL

只谈情不闲聊 提交于 2020-08-22 17:47:57
问题 I have the following table (SQL Server 2012): DID - cust id GID - order id AMT - order amt Gf_Date - order date SC - order reversal amount I'm trying to calculate a running count of orders and a running total of sales by customer so that I can assign a flag to the point in time where a customer achieved cumulative sales of $1,000. As a first step, I've run this query: Select [DID] , [AMT] , [Gf_Date] , COUNT([GID]) OVER (PARTITION BY [DID] ORDER BY [Gf_Date]) [RunningGift_Count] , SUM([AMT])

Calculating a running count & running total across customers with SQL

不羁的心 提交于 2020-08-22 17:47:07
问题 I have the following table (SQL Server 2012): DID - cust id GID - order id AMT - order amt Gf_Date - order date SC - order reversal amount I'm trying to calculate a running count of orders and a running total of sales by customer so that I can assign a flag to the point in time where a customer achieved cumulative sales of $1,000. As a first step, I've run this query: Select [DID] , [AMT] , [Gf_Date] , COUNT([GID]) OVER (PARTITION BY [DID] ORDER BY [Gf_Date]) [RunningGift_Count] , SUM([AMT])

How to Build select Query split Temp Value to two column one Per Number And Another to Text when Flag Allow 1?

佐手、 提交于 2020-08-10 23:24:50
问题 I work on a query for SQL Server 2012. I have an issue: I can't build select Query split Column Temp value to two Column When row in the temp table #nonparametric has the flag Allow = 1, it must split column Temp value from #nonparametric to two column when the flag Allow = 1 . suppose column Temp value has value 50.40 kg it must split to two column First column with number so it will have 50.40 and it will be same Name as Parametric . Second column with Text so it will have kg and it will be

Importing XML into SQL Server but trying to make multiple entries if multiple results exist for a child element

断了今生、忘了曾经 提交于 2020-08-09 09:03:48
问题 I have the following XML file that I import regularly into my SQL Server table files_index . Here is a small sample of XML below, my table layout and the Powershell code I use to insert the data. I use a PowerShell script from this answer The reason I am using PowerShell is that the file is 3.5gb so too big to use bulkinsert This solution works perfectly and has been for a while however I use the XML element Prod_ID when in the table the column Prod_ID to join my data with files supplied by