Skip to main content

Posts

Showing posts with the label Database

Replacing a carriage return (new line) in SQL query

Replace How to Remove/Replace carriage return in queries: Carriage returns inside the data plays havoc with export functionality.  Here is the simple way to remove or replace the carriage return with an alternate character using simple  Replace string function. The first replace changes the carriage return + new line char (\r\n), the next replace them if there are present separately. REPLACE(REPLACE(REPLACE(dbo.MyRemarkField , CHAR(10) + CHAR(13), ' '), CHAR(10), ' '), CHAR(13), ' ') AS MyRemarks,

SQL Server: How to find related db objects (views, stored procedure) for a table; Search stored procedures

The following code will help to find all the Stored Procedures (SP), Views, User defined functions which are related to one or more specific tables.  This is very useful since sp_help and sp_depends does not always return accurate results. SELECT DISTINCT SO.NAME, SO.XTYPE FROM syscomments SC INNER JOIN sysobjects SO ON SC.ID=SO.ID WHERE SC.TEXT LIKE '%tablename%'