Forum Replies Created

Viewing 14 posts - 76 through 89 (of 89 total)

  • RE: Convert String to a Table using CTE

    DECLARE @CommaSeparatorString VARCHAR(MAX),

    @CommaSeparatorXMLXML

    DECLARE @handle INT

    SELECT

    @CommaSeparatorString='1000<000 3000>,aamkmksd,ooi<></>,'

    SELECT

    @CommaSeparatorString=REPLACE(REPLACE(@CommaSeparatorString,'<','$^%'),'>','%^$')

    SELECT

    @CommaSeparatorXML=CAST('<ROOT><i>' + REPLACE(@CommaSeparatorString, ',', '</i><i>') + '</i></ROOT>' AS XML)

    SELECT

    @CommaSeparatorXML

    SELECT

    REPLACE(REPLACE(

    c.value('.', 'VARCHAR(100)'),

    '$^%','<'

    ),

    '%^$','>'

    )

    AS ID

    FROM

    (

    SELECT @CommaSeparatorXML AS CommaXML

    )a

    CROSS APPLY CommaXML.nodes('//i') x(c)

  • RE: Average of value for a period of timeinterval ,say every 4 hours

    DECLARE @tblHrTABLE

    (

    Date_Time VARCHAR(50),

    DATA VARCHAR(100)

    )

    INSERT INTO @tblHr

    SELECT

    '11/25/2009 00' , '1874'

    UNION

    SELECT

    '11/25/2009 01' , '2360'UNION

    SELECT

    '11/25/2009 02' , '2783'UNION

    SELECT

    '11/25/2009 03' , '2778'UNION

    SELECT

    '11/25/2009 04' , '2689'UNION

    SELECT

    '11/25/2009 05' , '2681'UNION...

  • RE: Convert String to a Table using CTE

    DECLARE @CommaSeparatorString VARCHAR(100),

    @CommaSeparatorXMLXML

    DECLARE @handle INT

    SELECT

    @CommaSeparatorString='1,2,3,4,5,6'

    SELECT

    @CommaSeparatorXML=CAST('<i>' + REPLACE(@CommaSeparatorString, ',', '</i><i>') + '</i>' AS XML)

    SELECT

    c.value('.', 'INT') AS ID

    FROM

    (

    SELECT @CommaSeparatorXML AS CommaXML

    )a

    CROSS APPLY CommaXML.nodes('//i') x(c)

  • RE: select the last month in SQL server 2005

    DECLARE @year VARCHAR(10)

    SELECT @year='2009'

    SELECT

    LEFT(CONVERT(VARCHAR,DATEADD(MM,number,@year),112),4)+' '+LEFT(DATENAME(MM,DATEADD(MM,number,@year)),3)

    FROM

    Master..spt_Values

    WHERE

    Type='p' AND

    number < DATEPART(MM,GETDATE())-1

  • RE: Aggregation with every N number of records grouped

    --===== If the test table already exists, drop it

    IF OBJECT_ID('TempDB..#Table_1','U') IS NOT NULL

    DROP TABLE...

  • RE: Find matching groups of rows

    DROP TABLE #TempTable

    CREATE TABLE #TempTable

    (

    GroupName varchar(25),

    FieldName varchar(25),

    ...

  • RE: REPLACE Multiple Spaces with One

    sorry for non-comments,as I avoid to write comments as my english is not that good.

    In first post I just used LTRIM and RTRIM with divide string into 2 part,

    simmlilarly in...

  • RE: REPLACE Multiple Spaces with One

    --===== Create and populate a test table

    IF OBJECT_ID('TempDB..#TestTable','U') IS NOT NULL

    DROP TABLE #TestTable

    SELECT TOP 1000 ...

  • RE: REPLACE Multiple Spaces with One

    Hi what abt this ?

    --===== Create and populate a test table

    IF OBJECT_ID('TempDB..#TestTable','U') IS NOT NULL

    DROP TABLE...

  • RE: REPLACE Multiple Spaces with One

    Hi what abt this ?

    --===== Create and populate a test table

    IF OBJECT_ID('TempDB..#TestTable','U') IS NOT NULL

    DROP TABLE...

  • RE: Nth occurrence of a weekday in a month and year

    IF OBject_ID('getNthOccuranceOfWeekDay') IS NOT NULL

    BEGIN

    DROP FUNCTION dbo.getNthOccuranceOfWeekDay

    END

    GO

    CREATE FUNCTION dbo.getNthOccuranceOfWeekDay

    (

    @year VARCHAR(4),

    @month TINYINT,

    @weekday TINYINT,

    @iOccAt TINYINT

    )

    RETURNS DATETIME

    AS

    BEGIN

    DECLARE @dt DATETIME, @dtNextMonth DATETIME,@retDate DATETIME,@WkTINYINT

    SELECT

    @dt= DATEADD(mm,@month-1,@year),--CAST(@year AS CHAR(4))+'-'+CAST(@month AS CHAR(2))+'-01'

    ...

  • RE: REPLACE Multiple Spaces with One

    please check this ,

    DECLARE @srtWord VARCHAR(8000)

    SELECT

    @srtWord = '1'+SPACE(7998)+'2'

    select @srtWord

    select @srtWord = REPLACE(REPLACE(REPLACE(CAST(@srtWord AS VARCHAR(MAX)),' ','$#$'),'$$#',''),'$#$',' ')

    select @srtWord

  • RE: REPLACE Multiple Spaces with One

    DECLARE @STR VARCHAR(1000)

    SET @STR= 'ALKSDKLKJ ...

  • RE: REPLACE Multiple Spaces with One

    DECLARE @STRVARCHAR(200)

    SELECT

    @STR ='Some day I will ...

Viewing 14 posts - 76 through 89 (of 89 total)