sql-server-2012

SELECT FOR XML AUTO and return datatypes

喜欢而已 提交于 2019-12-09 15:03:24
问题 During playing with sys.dm_exec_describe_first_result_set I get to this point: CREATE TABLE #tab(col INT, x XML ); INSERT INTO #tab(col,x) VALUES (1,NULL), (2,NULL), (3,'<a>x</a>'); SELECT 'Simple XML' AS description, name, system_type_name FROM sys.dm_exec_describe_first_result_set( N'SELECT col FROM #tab FOR XML AUTO', NULL, 0) UNION ALL SELECT 'Wrapped with subquery', name, system_type_name FROM sys.dm_exec_describe_first_result_set( N'SELECT(SELECT col FROM #tab FOR XML AUTO) AS wrapped

Is there an overview of all SQL Server 2012 error codes?

穿精又带淫゛_ 提交于 2019-12-09 14:16:26
问题 SQLGetDiagRec returns a native error code. Is there anywhere an overview of the error codes of SQL Server 2012? I couldn't find anything on MSDN. 回答1: I'm unable to find a list of the individual codes in the internet. However I did find a list of the severity levels here on MSDN. They are as follows: Severity level / Description 0-9: Informational messages that return status information or report errors that are not severe. The Database Engine does not raise system errors with severities of 0

Most efficient way to split string into rows

被刻印的时光 ゝ 提交于 2019-12-09 13:37:22
问题 I am using the following function to split a string into rows. It is much faster than the previous function that I was using, however I need to somehow churn through this data quicker (its an ETL job): ALTER FUNCTION [dbo].[ArrayToTable] ( @InputString VARCHAR(MAX) = '' , @Delimitter VARCHAR(1) = ',' ) RETURNS @RESULT TABLE([Position] INT IDENTITY, [Value] VARCHAR(MAX)) AS BEGIN DECLARE @XML XML SELECT @XML = CONVERT(XML, SQL_TEXT) FROM ( SELECT '<root><item>' + REPLACE(@InputString,

how to use msbuild properties in sqlproj (SQL Server 2012) script

随声附和 提交于 2019-12-09 11:24:45
问题 I just upgraded my existing SQL Server 2008 r2 .dbproj to a SQL Server 2012 .sqlproj (using SQL Server Data Tools). Previously, I was able to define a SQLCMD variable in my project, and then define the value by editing the project file to use msbuild values by adding the following element: <ItemGroup> <SqlCommandVariableOverride Include="ProjectDirectory=$(MSBuildProjectDirectory)" /> </ItemGroup> Which I could then use in my PostDeployment script like this: SELECT * INTO dbo.MyTable FROM dbo

How can LIKE '%…' seek on an index?

巧了我就是萌 提交于 2019-12-09 11:13:37
问题 I would expect these two SELECT s to have the same execution plan and performance. Since there is a leading wildcard on the LIKE , I expect an index scan. When I run this and look at the plans, the first SELECT behaves as expected (with a scan). But the second SELECT plan shows an index seek, and runs 20 times faster. Code: -- Uses index scan, as expected: SELECT 1 FROM AccountAction WHERE AccountNumber LIKE '%441025586401' -- Uses index seek somehow, and runs much faster: declare @empty

Generate Scripts - Data only - Cyclic dependencies found error

落爺英雄遲暮 提交于 2019-12-09 07:46:30
问题 I'm trying to generate a script of all the data in a database so I can move just the data over to an identical database on another server. In SQL Server 2012 I right click on the source database Tasks > Generate Scripts > Script entire database and all database objects > Advanced > Types of data to script: data only This gives me an error something about a Cyclic dependency. If I change the type of data to script to schema AND data it generates fine. How can I fix this to work with data only?

How do I create a new user in SQL Server 2012 that I can use in a connection string?

核能气质少年 提交于 2019-12-09 07:43:28
问题 I wasn't sure if this was a SO or SU question. I have freshly installed SQL Server 2012. I have created a database. I have a visual studio 2012 project, and I want to connect to the database using a connection string in my web config. Since I only have two accounts (sa and my windows account) I want to create a new user that will only have access to this one database. Google says, in SSMS, expand the database, right click Security and go to New User. However, when I do this and try to create

Passing multiple value parameters in SSRS to stored procedure

折月煮酒 提交于 2019-12-09 05:25:00
问题 I am trying to pass a multiple value string parameter to a table type parameter in a SQL Server 2012 stored procedure. I paste this code in the dataset of SSRS: DECLARE @mylist clinic_list_tbltype INSERT @mylist(n) VALUES (@pm_ChooseClinics) EXEC sp_Skillset_Summary_With_Callbacks_Report @mylist, @pm_ChooseInterval, @pm_StartDateTime, @pm_EndDateTime clinic_list_tbltype is a table type I created with one varchar(50) field named "n". I can call this stored procedure from SSMS o.k. like this

Can I print immediately for each iteration in a loop?

亡梦爱人 提交于 2019-12-09 00:18:08
问题 My deployment server runs a deployment script for every new database build. Part of the script blocks to wait for another asynchronous operation to complete. The blocking code looks like this: DECLARE @i INT = 0; DECLARE @laststatus NVARCHAR(MAX) = N''; WHILE @i < 5 BEGIN -- the real delay is longer WAITFOR DELAY '00:00:01'; -- poll async operation status here SET @i = @i + 1; SET @laststatus = N'status is ' + CAST(@i AS NVARCHAR(MAX)); RAISERROR(@laststatus, 0, 1) WITH NOWAIT; END; It uses

Alternatives to USING in a JOIN for SQL Server for avoiding duplicated columns in joined table

江枫思渺然 提交于 2019-12-08 22:34:27
问题 SQL Server does not offer the keyword USING in the context of a JOIN, nor it provides a NATURAL JOIN. Besides explicitly (manually) listing all the columns (link to otherwise duplicated question), is there an alternative to obtain a table in which the columns I am joining onto, which have the same name in the 2 joined tables, are not duplicated? As an intermediate step, I have tried to save in a temporary table the result SELECT INTO #MyTempTable * FROM tableA INNER JOIN tableB ON tableA