sql-server-2012

Query XML creating field names whithout knowing node names

六月ゝ 毕业季﹏ 提交于 2019-12-04 17:24:27
If I have a SQL SERVER 2012 table containing an XML field type. The records it could contain are as follows. I have simplified my problem to the following. Record 1: ID_FIELD='nn1' XML_FIELD= <KNOWN_NAME_1> <UNKNOWN_NAME1>Some value</UNKNOWN_NAME1> <UNKNOWN_NAME2>Some value</UNKNOWN_NAME2> ... Maybe more ... </KNOWN_NAME_1> Record 2: ID_FIELD='nn2' XML_FIELD= <KNOWN_NAME_2> <UNKNOWN_NAME1>Some value</UNKNOWN_NAME1> <UNKNOWN_NAME2>Some value</UNKNOWN_NAME2> ... Maybe more unknown fields ... </KNOWN_NAME_2> I want to output non xml: UNKNOWN_NAME1 | UNKNOWN_NAME2 | ETC ---------------------------

How to use OFFSET and Fetch without Order by in SQL Server

大憨熊 提交于 2019-12-04 16:52:31
问题 I want use OFFSET and Fetch in my SQL server 2012 query.But without any order by.I can not use order by.Because my sort order will be lost. How can I use OFFSET and Fetch without order by and row number and where in my query? My 2 select tables have same structure. INSERT INTO @TempTable [some columns] select [some columns] from table1 order by col1 INSERT INTO @TempTable [same columns] select [some columns] from table2 order by col2 select * from @TempTable OFFSET 20 ROWS FETCH NEXT 50 ROWS

Why CTE (Common Table Expressions) in some cases slow down queries comparing to temporary tables in SQL Server

拥有回忆 提交于 2019-12-04 16:48:32
问题 I have several cases where my complex CTE ( Common Table Expressions ) are ten times slower than the same queries using the temporary tables in SQL Server . My question here is in regards to how SQL Server process the CTE queries, it looks like it tries to join all the separated queries instead of storing the results of each one and then trying to run the following ones. So that might be the reason why it is so faster when using temporary tables. For example: Query 1 : using Common Table

Query to display spent credits from transactional table

坚强是说给别人听的谎言 提交于 2019-12-04 16:10:59
问题 I am working with a table that contains credit transactions where I want to display who's credits were spent when a sale is made. In the table: Credits are added by an entity using a unique entity code (recorded in column GivenByUserCode ) Credit additions always have such a code. Credits that are spent will always have a negative value. Credits that are spent will not have an entity code (value of GivenByUserCode is null ). Using the above data as an example if a user makes a purchase on

Geography data type vs. Geometry data type in SQL Server

♀尐吖头ヾ 提交于 2019-12-04 15:51:40
Environment: SQL Server 2012 I'm using an online tool, the only one I could find so far, to plot polygons and points on the earth. http://www.birdtheme.org/useful/googletool.html I have two tables. One stores "areas" as polygons and the other table stores points amongst other things irrelevant to my question. For simplicity, I'll just reduce my scenario to sql variables. In the query below, I'm using the geography data type for well known points of interest. I drew a polygon around Robben Island, a point in Robben Island and a point in Alcatraz. DECLARE @robben_island geography = ('POLYGON((18

C# & SQL Server - best way to delete multiple Rows in “one go” using a stored procedure

孤街浪徒 提交于 2019-12-04 15:51:35
I know there's many of the same subjected question here in SO, my question is if I want to delete say around 1K rows rather few, given a List<int> of RecordID , I could avoid using a DataTable , and send the list translated into a statement: string ParmRecordsToDelete_CsvWhereIN = "(" for(int CurIdx=0; CurIdx < RecIdsToDelete.Count; CurIdx++) { ParmRecordsToDelete_CsvWhereIN += RecIdsToDelete[CurIdx] + ", "; //this method to create passed parameter //logic to remove on last Coma on last Index.. //or use stringJoin and somehow remove the last coma } ParRecordsToDelete_CsvWhereIN +=")"; This

SQL Server 2012 not showing unicode character in results

痴心易碎 提交于 2019-12-04 14:47:22
All I want to do is update a field with the DIRECT CURRENT SYMBOL FORM TWO ⎓ character into my SQL Server 2012 database. Is that too much to ask? Apparently it is. The answer to this question and this question is the same and did not work for me. My update script UPDATE Table SET Value = N'SUPPLY 9-30Vdc 0.2W ⎓' WHERE id = '1234' Aaaaand the relevant table schema: CREATE TABLE [dbo].[Table] ( ... ... [Value] [nvarchar] (1000) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, ... ... ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] Want more? Here's the results of sp_columns : Yes, I prefixed the string with

Debugging in SQL Management Studio 2012

只谈情不闲聊 提交于 2019-12-04 12:58:15
I'm using Management Studio 2012 but I'm not able to debug any SQL code. After I hit the Debug button I'm not getting any green arrow on the left side and none of my SQL object are being loaded to the memory. I'm getting this message when I move my cursor over the breakpoint I set: The breakpoint will not currently be hit. Unable to bind SQL breakpoint at this time. Object containing the breakpoint not loaded. I followed a youtube video demonstrating how to debug in Studio 2012: http://www.youtube.com/watch?v=_jsFM_PUPgA&feature=relmfu The guy in the video around 4:30 writes a small SQL query,

how does one programmatically create a localdb .mdf?

心已入冬 提交于 2019-12-04 12:22:36
how does one programmatically create a localdb .mdf? acceptable solutions exclude visual studio, ssms, aspnet_regsql. a naive stab at a solution might look like this: static void Main(string[] args) { using (var con = new SqlConnection(@"Integrated Security=SSPI;Data Source=(LocalDb)\v11.0;AttachDbFilename=test.mdf")) { con.Open(); using (var cmd = new SqlCommand("CREATE DATABASE test", con)) { cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } } } but of course, this fails in SqlConnection.Open with the error An attempt to attach an auto-named database for file test.mdf failed. A

what is the proper install order for visual studio 2012 and SQL Server Management Studio 2012 on win7?

一笑奈何 提交于 2019-12-04 12:02:56
问题 I am preparing to do some web development against a SQL Server 2012 server on a fresh install of win 7 x64 development VM. What should I install first, visual studio or SSMS? 回答1: Neither - you can install them in any order. While you do get the occasional question about it in various different forums, I have done this and never had an issue. SQL does have a Visual Studio dependency (formerly) called BIDS, but Visual Studio can install over/around this no problem. Note that this answer is