Format:
Recent snippets matching tags of tsql
ALTER DATABASE database-name SET OFFLINE WITH ROLLBACK IMMEDIATE
24 Views
no comments
DECLARE @count int DECLARE @query nvarchar(max) SET @query = 'SELECT @count = count(*) from MyTableName' EXEC sp_executesql @query, N'@count int OUTPUT', @count output
47 Views
no comments
ALTER PROCEDURE [dbo].[pr_OrderItem_history] ( @PipCode varchar(50), @BarCode varchar(150), @Status Char(10) ) AS BEGIN select PID.PO_ItemID,
82 Views
no comments
create function dbo.fn_SpacePascal(@in varchar(500)) RETURNS varchar(500) begin /* by: jerry on: 5/2011 to: seperate PascalCaseWords to Pascal Case Words */ if (@in COLLATE Latin1_General_CS_AS = UPPER(@in))
170 Views
no comments
CREATE FUNCTION [dbo].[udf_StringToTable] ( @string VARCHAR(MAX), @delimiter CHAR(1) ) RETURNS @output TABLE( data VARCHAR(256) ) BEGIN
109 Views
no comments
create function dbo.fn_SpacePascal(@in varchar(500)) RETURNS varchar(500) begin /* by: jerry on: 5/2011 to: seperate PsacalCaseWords to Pascal Case Words */ if (@in COLLATE Latin1_General_CS_AS = UPPER(@in))
171 Views
no comments
CREATE FUNCTION [dbo].[udf_DatesInRange] ( -- Add the parameters for the function here @StartDateTime DateTime, @EndDateTime DateTime ) RETURNS @Dates TABLE ( DateInRange DateTime )
118 Views
no comments
Set NoCount ON Declare @tableName varchar(200) set @tableName='' While exists (
267 Views
no comments
DECLARE @RandomNumber float DECLARE @RandomInteger int DECLARE @MaxValue int DECLARE @MinValue int SET @MaxValue = 4 SET @MinValue = 2 SELECT @RandomNumber = RAND()
423 Views
no comments
-- Disable All constraint (FK) EXECUTE sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT ALL" GO -- Enable EXECUTE sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL" GO
302 Views
no comments
set nocount on use tempdb if (object_id('x') is not null) drop table x create table x (id int primary key identity(1, 1), date datetime, value bigint, total bigint) declare @x table(id int, date datetime, value bigint, total bigint) declare @d datetime
437 Views
1 comments
declare @x int, @y int, @z int set @x = 1 set @y = 2 set @z = 1 -- returns @x (because not equal) select case when @x = @y then null else @x end -- returns null (because equal) select case when @x = @z then null else @x end
652 Views
no comments
-- clean up any test artifacts if object_id('test1') is not null drop table test1 if object_id('test2') is not null drop table test2 if object_id('test') is not null drop view test GO -- the partition column must have a CHECK -- and be part of the PRIMARY KEY create table test1 (col1 int primary key check (col1 = 1), col2 varchar(50))
374 Views
no comments
CREATE TABLE table1 (id int); INSERT INTO table1 VALUES (1); INSERT INTO table1 VALUES (2); INSERT INTO table1 VALUES (3); CREATE TABLE table2 (id int); INSERT INTO table2 VALUES (2); INSERT INTO table2 VALUES (3); CREATE TABLE table3 (id int);
319 Views
2 comments
SELECT SERVERPROPERTY('BuildClrVersion') AS [BuildClrVersion] GO SELECT SERVERPROPERTY('Collation') AS [Collation] GO SELECT SERVERPROPERTY('CollationID') AS [CollationID] GO SELECT SERVERPROPERTY('ComparisonStyle') AS [ComparisonStyle] GO SELECT SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS [ComputerNamePhysicalNetBIOS] GO
472 Views
no comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
