sql-server-2014

Trouble Getting XML Data into relational format in SQL Server 2014

杀马特。学长 韩版系。学妹 提交于 2019-12-11 06:57:49
问题 I'm getting some XML data that I need to 'shred' (I think that's the right term). That is I need to put it into a SQL table. Here's an example, and a query that works, but I was told it was inefficient. Please let me know if you know a more efficient way to do this. Here's some example XML, 2 queries that don't work, and one that does: DECLARE @XmlReportParameters NVARCHAR (MAX) = N'<?xml version="1.0" encoding="utf-16"?> <Customers> <Customer> <Name>Sri Patel</Name> <FavColors> <FavColor>Red

Group Non-Contiguous Dates By Criteria In Column (Follow Up)

十年热恋 提交于 2019-12-11 06:35:55
问题 I had this question answered in this post but have been advised to re-ask this as a new question: Group Non-Contiguous Dates By Criteria In Column However, I have noticed that while the solution works most of the time, there are some errors which trickle through where it doesn't seem to group things together correctly. For Example, Data: DECLARE @TempTable TABLE([CUSTOMER_ID] INT ,[TEAM] VARCHAR(1) ,[TYPE] VARCHAR(1) ,[START_DATE] DATETIME ,[END_DATE] DATETIME ,[GROUP_DAYS_CRITERIA] INT)

SQL Server 2014: Regex to substring

限于喜欢 提交于 2019-12-11 06:35:48
问题 In SQL SERVER 2014 how to use regex to extract string ? example: CN=John Lee 709123,ou=Users,OU=LA-US1242,OU=US,OU=nam,DC=DIR,DC=ABB,DC=com SQL will return John Lee The regex is ^CN=([^0-9]+) but how to applied this regex is SQL ? 回答1: RegEx and SQL Server are not the best friends... You might try it like this: DECLARE @s NVARCHAR(100)=N'CN=John Lee 709123,ou=Users,OU=LA-US1242,OU=US,OU=nam,DC=DIR,DC=ABB,DC=com'; WITH Splitted AS ( SELECT CAST('<x>' + REPLACE(@s,',','</x><x>') + '</x>' AS XML

Separate Potential Duplicates Into Different Rows

岁酱吖の 提交于 2019-12-11 06:11:29
问题 I am trying to identify potential duplicate customers in my database based on the last 4 of the SSN, last name and DOB. The stored procedure I have written does identify potential duplicates but it lists them in one row - I am trying to split into separate rows for reporting reasons. My T-SQL looks like: DECLARE @StartDate DATE = '1/1/2017', @EndDate DATE = '3/1/2017'; SELECT DENSE_RANK() OVER (ORDER BY c.socialSecurityNumber) AS [SSNRanking] , ROW_NUMBER() OVER (PARTITION BY c

Error with OLEDB provider New transaction cannot enlist in the specified transaction coordinator

我怕爱的太早我们不能终老 提交于 2019-12-11 05:18:16
问题 using (TransactionScope transactionscope = new TransactionScope()) { try { function1(); //perform update on table function2(); //perform update on table transactionscope.Complete(); } catch(Exception ex) { } } Code working fine with sqlclient provider but in case of oledb provider it gives error "New transaction cannot enlist in the specified transaction coordinator". Already enable DTC service on server. 回答1: You can not open connection in transaction more than one, so create connection

cursor with sp_executesql and parameters

跟風遠走 提交于 2019-12-11 05:15:57
问题 I am hoping for some further help with an issue I have been struggling with, I did post a similar question yesterday but I think the example I was using was to complicated for what I wanted so I decided to start from scratch and write my own. As previously stated I have a table with a number of sql statements in it and I want to run each in turn and update the same table with the result as well as the time that I ran the code. My code so far runs through each SQL statement and executes it but

SQL Server stored procedure looping through a comma delimited cell

依然范特西╮ 提交于 2019-12-11 05:01:19
问题 I am trying to figure out how to go about getting the values of a comma separated string that's present in one of my cells. This is the query I current am trying to figure out in my stored procedure: SELECT uT.id, uT.permissions FROM usersTbl AS uT INNER JOIN usersPermissions AS uP /*Need to loop here I think?*/ WHERE uT.active = 'true' AND uT.email = 'bbarker@thepriceisright.com' The usersPermissions table looks like this: And so a row in the usersTbl table looks like this for permissions :

T-SQL (Cross?) Joins

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 04:49:32
问题 Code: DECLARE @T1 TABLE (ID INT, Val1 VARCHAR(25), Val2 VARCHAR(25)); DECLARE @T2 TABLE (ID INT, Val3 BIT); DECLARE @T3 TABLE (ID INT, Val4 DECIMAL(18,6)); INSERT INTO @T1 ( [ID], [Val1], [Val2] ) VALUES ( 1, 'V1One','V2One' ) ,(2, 'V1Two','V2Two' ) ,(3, 'V1Three','V2Three' ) ,(4, 'V1Four','V2Four' ); INSERT INTO @T2 ( [ID], [Val3] ) VALUES ( 3, 1 ); INSERT INTO @T3 ( [ID], [Val4] ) VALUES ( 4, 9.99 ) ,( 5, 0.99 ); Desired Output: ID Val1 Val2 Val3 Val4 1 V1One V2One NULL NULL 2 V1Two V2Two

Calculate group result and merge it with details

旧街凉风 提交于 2019-12-11 04:23:37
问题 Please consider this result (Report): State Value1 Value2 Value3 --------------------------------------------- State1 103 23% 3 State2 105 32% 12 State3 150 2% 23 Group1 120 19% 3 =================== State4 200 40% 5 State5 250 2% 12 Group2 225 21% 8 =================== ... I have groups and each group contains some states. No I want to run a query on my details data and run some custom function on each group to obtain Value1 to Value3 . For simplicity consider AVG function. I'm using Group

Is there a way to select last N columns in SQL Server Results Tab?

徘徊边缘 提交于 2019-12-11 04:06:04
问题 Shortly, I don't mean the last 5 rows. via SELECT TOP 5 * FROM Table Order By Key DESC But I mean last 5 columns in Results Tab. Why? because each time I add a new column and filling it outside SQL-Server, I need to see its result without moving Horizontal Scroll. and many columns have the same name at the beginning. It's not coding issues. but it's about the SQL-Server IDE Results tab itself. I Searched many times. but this thing never asked I think. so please I want an approach for that. I