sql-server-2012

select case with “over partition by”

柔情痞子 提交于 2019-12-11 10:43:20
问题 What's the correct syntax or is it possible to use case in a select and in it partition by? (using sql server 2012) a = unique id b = a string'xf%' c = values d = values e = values select case when b like 'xf%' then (sum(c*e)/100*3423 over (partition by a))end as sumProduct from #myTable this is something i need to solve which is a part of a problem i had previously sumProduct in sql edit : upon request adding some sample data and expected result create table #testing (b varchar (20), a date,

Can you export SQL Server 2012 data into an XML file

穿精又带淫゛_ 提交于 2019-12-11 10:35:22
问题 Below is a very small example of the SQL and XML but no idea how to export this into say C:\Users\Simon.Evans\Documents\Test.xml. To be fair I have very little to zero knowledge of XML so walking in the dark. Ultimately I am trying to find a way to export for SQL tables into an XML file. SELECT patient.OID AS '@ID', patient.FORENAME, patient.SURNAME, patient.TITLECODE, patient.BIRTHDTTM FROM HealthBI.dbo.LZO_PATIENT patient WHERE patient.OID = '3400000000' FOR XML PATH('Patient'), ROOT(

SQL - Retrieve data pagewise

拈花ヽ惹草 提交于 2019-12-11 10:34:57
问题 I have a stored procedure which returns a list of contacts. Since there are many contacts, and for performance reasons, I wish to retrieve the contacts in a page-wise manner, whereby only 20 contacts are fetched in the each instance. A button on my form will allow me to go to the next page, and once the button is clicked, I go and fetch the next 20 contacts. Here's my stored proc; CREATE PROCEDURE [dbo].[GetAllContacts] (@searchVal VARCHAR(500)) AS BEGIN SELECT DISTINCT ( Id ) AS Id,

Build and Deploy SSIS packages using VSTS

試著忘記壹切 提交于 2019-12-11 09:59:00
问题 I created the simple SSIS project in VS2015 with SQL Server 2012 as a targeted server, it will worked in local machine successfully without any issues. After that I have created the build definition and release definition by following this link. For this project build will be success. But release definition failed with this “##[error]Task_InternalError Exception calling ".ctor" with "1" argument(s): Failed to connect to server DNS name label.eastus.cloudapp.azure.com,1433" error message in

Appending data in T-SQL

两盒软妹~` 提交于 2019-12-11 09:58:27
问题 I have a sql (transact sql - SQL server 2012) which used to fetch names of customers from a table (Customer) who has valid addresses (from table Details): Select Customer.Name, Details.Address from Customer left outer join Details on Details.Customer = Customer.Name This used to send back each record (name) row for each customer every time from the db server. No multiple records are fetched. Recently I needed to modify this sql text in order to fetch even the name of the books they have

Dynamic MS SQL Variable Parsing incorrectly

假装没事ソ 提交于 2019-12-11 09:44:10
问题 I have got an issue with Dynamic Variable Parsing incorrectly and I don't know a way around it. Here is an example: DECLARE @tableName varchar(20), @columnName varchar(20), @prompt varchar(20) DECLARE @dynSQL varchar(500) set @tableName = '[A1-ExciseESN]' set @columnName = '[Anode Excise ESN (A1)]' @dynSQL = 'INSERT INTO ' + @tableName +' ([trav num], '+@columnName+') Select [trav num], '+@columnName+' FROM [temprmi$] t1 PIVOT(min([Lvl1 Trace Data]) FOR [Prompt Text] IN ('+@columnName+' ) )

“An error occurred during Service Master Key decryption” when trying to create SSIS catalog

空扰寡人 提交于 2019-12-11 09:35:47
问题 I'm trying to follow the guide to Create the SSIS Catalog on my Developer instance of SQL 2012 and I'm receiving the follow error: =================================== An error occurred during Service Master Key decryption Changed database context to 'SSISDB'. (.Net SqlClient Data Provider) ------------------------------ For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=11.00.5058&EvtSrc=MSSQLServer&EvtID=33094&LinkId=20476 ------------------------------

Configure SQL server to store session state

末鹿安然 提交于 2019-12-11 09:05:57
问题 I am trying to set up session state in SQL server. Command: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regsql.exe -ssadd –sstype c -d SomeName -S SERVERNAME -U someUser -P somePass It throws: The argument '-sstype' is invalid. Any tips? 回答1: Stupid. C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regsql.exe -ssadd -d SomeName -S SERVERNAME -U someUser -P somePass –sstype c The arguments order... 回答2: You need to enable Agent XPs to run Aspnet_regsql.exe tool From Installing

How to remove duplicates from a string in SQL

我与影子孤独终老i 提交于 2019-12-11 08:37:41
问题 I got a column in my SQL table where some values are seperated bij " . Some values in this string are duplicated which I want to remove. Here is an example of my data: --------------- | qw"qw"er"er | --------------- | q"w"w"q | --------------- | f"k"s"g | --------------- Now The result should replace any duplicates: --------------- | qw"er | --------------- | q"w" | --------------- | f"k"s"g | --------------- So first I want to split the string and then remove duplicates. Could anyone help me

Gridview Freeze Pane header not freezing after page loads

99封情书 提交于 2019-12-11 08:30:01
问题 Browser - IE 9 Using the Latest Version of Microsoft's AdventureWorks2012 sandbox database (AdventureWorks2012_Data.zip) for SQL related Data. I had to put this project on the backburner a few months ago due to various job interrupts and whatnot. What I'm looking for is a GridView that when it loads has a frozen header while the enduser scrolls the large amounts of data. Where I left off was a product that, upon first load would look good but when the data was scrolled the header I want