The performance issue with Table variables with many rows and then join it with other tables has ben fixed by as explained in KB2952444. Before the fix which applied to SQL Server 2012 SP2 and later, the query optimizer may choose an inefficient query plan, which may lead to slow query performance.
https://support.microsoft.com/en-us/kb/2952444
Tuesday, September 22, 2015
Tuesday, September 15, 2015
AngularJS Style Guide by John Papa
AngularJS Style Guide by John Papa
https://github.com/johnpapa/angular-styleguide
AngularJS Style Guide by John Papa
T-sql :: Change just DATE part of a DATETIME
Tuesday, July 7, 2015
Set date to first day of the month and end day of the month
Set date to first day of the month:
Set date to end day of the month:
Set date to last day of the previous month:
Remove milliseconds from datetime:
SELECT DATEADD(m, DATEDIFF(m, 0, GETDATE()), 0)
Set date to end day of the month:
SELECT EOMONTH(GETDATE())
Set date to last day of the previous month:
SELECT EOMONTH(GETDATE(), -1)
Remove milliseconds from datetime:
DECLARE @now DATETIME
SET @now = GETDATE()
SELECT @now
SELECT DATEADD(ms, -DATEPART(ms, @now), @now)
Set date to first day of the month and end day of the month
Friday, February 27, 2015
Visual Studio Error List and Output Window shortcuts
Wednesday, February 11, 2015
Visual Studio Immediate Window shortcut
Monday, September 8, 2014
Unable to update the EntitySet ‘Table’ because it has a DefiningQuery and no element exists in the element to support the current operation
Entity Framework tried to add a record to a table which had Clustered Index but it didn't have Primary Key.
Simple solution was adding the Primary Key.
the reason is treating the table as View, then the EDMX file keep the table as a view in StorageModel\EntitySet\DefiningQuery element. When there is a DefiningQuery the Entity becomes readonly unless you add modification functions, the other solution can be adding modification functions like Stored Procedures for Inserting, Updating, and Deleting.
Simple solution was adding the Primary Key.
the reason is treating the table as View, then the EDMX file keep the table as a view in StorageModel\EntitySet\DefiningQuery element. When there is a DefiningQuery the Entity becomes readonly unless you add modification functions, the other solution can be adding modification functions like Stored Procedures for Inserting, Updating, and Deleting.
Unable to update the EntitySet ‘Table’ because it has a DefiningQuery and no element exists in the element to support the current operation
Tuesday, August 19, 2014
Friday, June 27, 2014
SQL - Break execution of a SQL script
SET NOEXEC ON
SET NOEXEC ON skips the rest of the script but it does not terminate the connection.
To execute any other command you need to turn noexec off again.
OR
RAISERROR('Your error message', 20, -1) WITH log
This will terminate the connection, thereby stopping the rest of the script from running.
If you are logged in SQL as [admin] ('sysadmin' role), the RAISERROR will terminate the connection and stops the script from running the rest of code.
(If you are not logged in as [admin], otherwise the RAISEERROR() will fail and the script will continue executing.) Note that it requires both severity 20 (or higher) and "WITH LOG".
SQL - Break execution of a SQL script
Recursive SQL CTE to split CSV string to table rows
DECLARE @strCSV VARCHAR(8000)
, @delimiter CHAR(1)
SET @delimiter = ','
SET @strCSV =
'001002330
,001012657
,001046228
,001105047
,001138189'
DECLARE @TableVariable TABLE
(
ID INT,
Item VARCHAR(12)
)
;WITH RegNumStartEndIndexes AS(
SELECT
StartIndex = 0
, EndIndex = CHARINDEX(@delimiter,@strCSV)
UNION ALL
SELECT
EndIndex+1
, CHARINDEX(@delimiter,@strCSV,EndIndex+1)
FROM RegNumStartEndIndexes
WHERE EndIndex>0
)
INSERT INTO @TableVariable (ID, Item)
SELECT
ROW_NUMBER() OVER(ORDER BY(SELECT 1)) AS ID
, REPLACE( REPLACE( SUBSTRING(@strCSV, StartIndex,
COALESCE(NULLIF(EndIndex,0), LEN(@strCSV)+1)-StartIndex),
CHAR(13), ''), CHAR(10), '') AS Item
FROM RegNumStartEndIndexes
option (maxrecursion 0)
-- [option (maxrecursion 0)] added To avoid following error when number of recursions gets high
-- The maximum recursion 100 has been exhausted before statement completion
SELECT *
FROM @TableVariable
Originally grabbed the idea from here
Recursive SQL CTE to split CSV string to table rows
Subscribe to:
Posts (Atom)