Category "tsql"

Transpose results of a sql query

How to transpose this display. SeqNo Step Date By 1 Quoted 2018-03-01 Person1 2 Checked 2018-03-02 Person2 3 A

Is there another way to write SUM(IIF([CONDITION], 1, 0))?

What SUM(IIF([CONDITION], 1, 0)) does is very simple. So simple, that what I really just want to write is COUNT([CONDITION]) (but that's invalid). Is there a sh

Are there cons to generating GUIDs with a stored procedure using NEWSEQUENTIALID?

My goal is to create a stored procedure that generates new GUIDs using NEWSEQUENTIALID that can then be used when inserting data into a different table in the s

T-SQL hierarchy query

I have a table with hierarchical data: This is a sample of data with id, parent id, name, code (which is sometimes not filled), level and isroot column. In r

Are there any advantages in using a single stored procedure for multiple operations or is my teacher wrong? [closed]

I'm working on my databases class final project, which consists of making an application that can access and do operations in a database. My t

MS SQL: extremely slow query with 4 OR condition, but each condition alone run very quickly

I have two physical tables: notTempBaseLine with 50k records (index on Version, SrcDimension2_) notTempTrans with 400k records (index on BaseLineVersion, Dimens

SSIS Alternatives to one-by-one update from RecordSet

I'm looking for a way to speed up the following process: I have a SSIS package that loads data from Excel files on a weekly basis to SQL Server. There are 3 fi

How to perform a LEFT JOIN on the same table using Linq?

Consider a table where rows may be linked to each other. We need to select the rows that meet a certain requirement, OR where its linked row meets that requirem

SELECT returns NULL if run from application

I have an INSERT trigger on a view created with VIEW_METADATA. There's the following snippet: if @has_folder is null set @has_folder=(select REPLACE(REPLAC

SQL Server TRUNCATE

I have a question to the TRUNCATE command. How does TRUNCATE work in background ? I read a text that says TRUNCATE creates a copy from the table and then star

Rolling COUNT DISTINCT of n-day active users using T-SQL

I am counting 7-day active users using T-SQL. I used the following code: SELECT *, COUNT(DISTINCT [UserID]) OVER ( PARTITION BY [HospitalID],

Make directory in Using SQL xp_create_subdir

CREATE PROCEDURE SPCheckDirectoryExists ( @chkdirectory as nvarchar(4000) ) AS SET NOCOUNT ON BEGIN DECLARE @folder_exists as int DECLA

How to copy file without using XP_CMDSHELL?

I am using SQL Server 2008. I would like to give users possibility to copy files. Is it possible without using XP_CMDSHELL procedure? Cause i should not change

How do I go back to multi_user mode

Here is my query: IF EXISTS(%some query%) BEGIN BEGIN TRY ALTER DATABASE [MyDatabase] SET single_user WITH ROLLBACK IMMEDIATE; --d

Visual Studio errors SQL71501 and SQL71508 with a certificate?

I've seen problems like these with users before, but never with a certificate. I have a simple certificate with no keys: CREATE CERTIFICATE [FOO_EXPORT] AUTHORI

Query to display Employee and Manager

I have to write a SQL Server query to display the employee last name and his respective manager’s name, as given below. John works for Robert Jane works f

SQL Server after update trigger

I have a problem with this trigger. I would like it to update the requested information only to the row in question (the one I just updated) and not the entire

How to view test results in tSQLt?

We are using tSQLt for unit testing our database and executed below: EXEC tSQLt.Run '[testComplianceDimensions].[test CountOfPropertiesWithLatestRepairJob]' EXE

Store Procedure Result to Text file using SSIS package

Here i am new in Developing the SSIS package I need your support to come up with the solution. I have 10 different set of stored procedures which I have to ex

Test for Upper Case - T-Sql

All, How can I check if a specified varchar character or entire string is upper case in T-Sql? Ideally I'd like to write a function to test if a character is u