Skip to content

Instantly share code, notes, and snippets.

View jotapardo's full-sized avatar
🏠
Working from home

Javier Pardo jotapardo

🏠
Working from home
  • Colombia
View GitHub Profile
@jotapardo
jotapardo / GetFieldStringTruncate.sql
Created October 19, 2018 19:41
This procedure is intended to help identify and resolve the problem of text truncation (String or binary data would be truncated) when the INSERT SELECT statement is used. It compares fields CHAR, VARCHAR, NCHAR AND NVARCHAR only and returns an evaluation field by field in case of being the possible cause of the error. SQL SERVER.
DECLARE @strSQL nvarchar(1000)
IF NOT EXISTS (SELECT * FROM dbo.sysobjects where id = OBJECT_ID(N'[dbo].[GetFieldStringTruncate]'))
BEGIN
SET @strSQL = 'CREATE PROCEDURE [dbo].[GetFieldStringTruncate] AS RETURN'
EXEC sys.sp_executesql @strSQL
END
GO
SET ANSI_NULLS ON
@jotapardo
jotapardo / GetListOfTempTables.sql
Last active January 5, 2017 13:54
Get a list of temporary tables created in a stored procedure
DECLARE @NameStoreProcedure AS VARCHAR(100) = 'Name_of_store_procedure' --Do not place the scheme
IF NOT EXISTS (SELECT * FROM dbo.sysobjects where id = OBJECT_ID(@NameStoreProcedure))
BEGIN
SELECT 'Invalid store procedure name ' + @NameStoreProcedure
RETURN
END
IF OBJECT_ID('tempdb..#Positions') IS NOT NULL
DROP TABLE #Positions
@jotapardo
jotapardo / dbo.TRY_CAST.sql
Last active June 1, 2022 13:11
TRY_CAST Function for SQL Server 2008
DECLARE @strSQL NVARCHAR(1000)
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[TRY_CAST]'))
BEGIN
SET @strSQL = 'CREATE FUNCTION [dbo].[TRY_CAST] () RETURNS INT AS BEGIN RETURN 0 END'
EXEC sys.sp_executesql @strSQL
END
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON