sql-server-2014

How can I conditionally include large scripts in my ssdt post deployment script?

て烟熏妆下的殇ゞ 提交于 2019-12-06 03:37:48
In our SSDT project we have a script that is huge and contains a lot of INSERT statements for importing data from an old system. Using sqlcmd variables, I'd like to be able to conditionally include the file into the post deployment script. We're currently using the :r syntax which includes the script inline: IF '$(ImportData)' = 'true' BEGIN :r .\Import\OldSystem.sql END This is a problem because the script is being included inline regardless of whether $(ImportData) is true or false and the file is so big that it's slowing the build down by about 15 minutes. Is there another way to

how to migrate or copy SSRS datasource from one server to another without restoring the report server

久未见 提交于 2019-12-05 23:56:23
I'm trying to migrate SSRS report from SQL 2008r2 to SQL 2014 server. I used reportsync to transfer the report to the server. the reports are successfully transferred but however the roles subscriptions and datasources are not transferred. Is there is any way to copy or migrate the data sources, roles and subscription from one server to another without restoring the report server database?. Thanks. I have used these migration tools which doesn't help me much. i found the below link after a lot of struggle trying different things https://azuresql.codeplex.com/releases/view/115207 https://msdn

How to distinguish between day and night shifts by looking at past sign in times?

ε祈祈猫儿з 提交于 2019-12-05 21:15:43
Currently, the report uses predefined times. But sometimes employees overstay their shift and they creep into the next shift report. How do I modify the report query to look at the past sign in times to avoid this? In the TIMEATT column 1 is entry and 2 is exit. Light blue highlights the correct entries and yellow signify incorrect entries. Day shift report for 29th has 'Done, Jane's' entry time from night shift Night shift report for 29th has 'Do, Jone's' entry time from day shift Below query creates a temp table with the same data as in the screenshots. CREATE TABLE #temptable ( [Company]

Update and Insert When Condition is Matched in TSQL-Merge

こ雲淡風輕ζ 提交于 2019-12-05 20:26:35
I have been trying to Write a Stored Procedure where i can perform UpSert using Merge with the Following Condition If Record is Present then change EndDate of Target to Yesterday's day i.e., Present Day - 1 If Record is not Present then Insert New Record Here is the Table tblEmployee i used in SP CREATE TABLE tblEmployee ( [EmployeeID] [int] IDENTITY(1,1) NOT NULL, [Name] [varchar](10) NOT NULL, [StartDate] [date] NOT NULL, [EndDate] [date] NOT NULL ) Here is my SP which Takes UDTT as Input parameter CREATE PROCEDURE [dbo].[usp_UpsertEmployees] @typeEmployee typeEmployee READONLY -- It has

Bulk insert from CSV file - skip duplicates

喜夏-厌秋 提交于 2019-12-05 19:19:30
UPDATE: Ended up using this method created by Johnny Bubriski and then modified it a bit to skip duplicates. Works like a charm and is apparently quite fast. Link: http://johnnycode.com/2013/08/19/using-c-sharp-sqlbulkcopy-to-import-csv-data-sql-server/ I have been searching for an answer to this but cannot seem to find it. I am doing a T-SQL bulk insert to load data into a table in a local database from a csv file. My statement looks like this: BULK INSERT Orders FROM 'csvfile.csv' WITH(FIELDTERMINATOR = ';', ROWTERMINATOR = '0x0a', FORMATFILE = 'formatfile.fmt', ERRORFILE = 'C:\\ProgramData\

SQL Server: change first day of week to Sunday using DATEPART with ISOWK parameter

故事扮演 提交于 2019-12-05 19:19:19
I need to get week numbers for some set of dates. For example, for Jan 2016 it should be something like: [Week Number] 53 <--- for dates from Jan 1 to Jan 2 1 <--- for dates from Jan 3 to Jan 9 2 <--- for dates from Jan 10 to Jan 16 ... <--- etc. As you see, week should start from Sunday. I've used following function to set start day: SET DATEFIRST 7 And this one to get week number: DATEPART(ISOWK, SOME_DATE) But I've noticed that DATEFIRST doesn't affect results when ISOWK being used - week always starts from Monday. So, what am I doing wrong? Thank you! UPD: I've made a function, seems it

SQL create database if not exists, unexpected behaviour

与世无争的帅哥 提交于 2019-12-05 12:23:54
问题 I have a long stored procedure which begins with the following statement: IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = N'DBNAME') BEGIN CREATE DATABASE [DBNAME] END; It is expected to create the DB on my local server, if it does not exist. The problem is that almost all of the time it goes thorugh this part of the stored procedure and does not create it, which then interferes with the other code from the same procedure. On the other hand, in very rare cases, it creates the DB. My

Sorting month name in dynamic pivot

一个人想着一个人 提交于 2019-12-05 12:21:49
I produced a dynamic pivot with the following query which work but the column (monthyear) are in alphabetical order but I want them in chronological order The monthyear column is derived using a function in SQL Server 2014 CREATE TABLE ##MyTable (Num VARCHAR(10), StartDate DATE, [Types] VARCHAR(10)) INSERT INTO ##MyTable VALUES ('AA1','2016-01-01', 'Type1'),('AA2','2017-01-04', 'Type1'),('AA3','2016-01-04', 'Type1'),('AA4','2017-01-01', 'Type2'), ('AA5','2017-01-10', 'Type3'),('AA6','2016-01-02', 'Type1'),('AA7','2017-01-05', 'Type1'),('AA8','2016-01-12', 'Type1'), ('AA9','2016-01-06', 'Type1'

The value is returned instead of NULL when using function with OUTER APPLY

橙三吉。 提交于 2019-12-05 11:04:50
问题 I am getting strange results when using inline function. Here is the code: IF EXISTS ( SELECT * FROM sys.objects AS o WHERE name = 'vendor_relation_users' ) DROP FUNCTION dbo.vendor_relation_users; GO CREATE FUNCTION [dbo].[vendor_relation_users] ( @user_name CHAR(12) ) RETURNS TABLE AS RETURN (SELECT @user_name AS user_name WHERE @user_name NOT LIKE '06%'); GO DECLARE @u CHAR(12) = '066BDLER' SELECT a.user_name, is_v.user_name FROM (SELECT @u AS user_name) a OUTER APPLY [dbo].[vendor

SQL Server bug or feature? Decimal numbers conversion

喜欢而已 提交于 2019-12-05 10:00:41
问题 During development faced up with quite a strange SQL Server behavior. Here we have absolutely the same formula for absolutely the same number. The only difference is how we are getting this number (4.250). From table, temp table, variable table or hardcoded value. Rounding and casting is absolutely the same in all cases. -- normal table CREATE TABLE [dbo].[value] ( [val] [decimal] (5, 3) NOT NULL ) INSERT INTO [value] VALUES (4.250 ) SELECT ROUND(CAST(val * 0.01 / 12 AS DECIMAL(15, 9)), 9) AS