SQL

Get Data in Comma Separated String From SQL Database Table


DECLARE @CommaSeparatedString NVARCHAR(MAX);
SELECT  @CommaSeparatedString = STUFF ((SELECT ',' + CONVERT (NVARCHAR, ColumnaName)
                             FROM   dbo.TableName
                             WHERE  ConditionalColumn = -1
                            FOR XML PATH ('')), 1, 1, '');

PRINT @CommaSeparatedString;

-------------------------------------------------------------------------
-------------------------------------------------------------------------

Search Specific Text in All Stored Procedure in Database


USE [Test_DB];

SELECT  DISTINCT
        o.name AS Object_Name
      , o.type_desc
FROM    sys.sql_modules m
        INNER JOIN sys.objects o ON m.object_id = o.object_id
WHERE   m.definition LIKE '%TextToSearch%';

-------------------------------------------------------------------------
-------------------------------------------------------------------------

No comments:

Post a Comment

Configure Console Application as Windows Service

  To configure a  console application  as a  Windows Service , you'll need to follow several steps, which typically involve writing a se...