Forum Replies Created

Viewing 15 posts - 31 through 45 (of 89 total)

  • RE: Query Help Needed

    SELECT T1.StudentID,StudentName, StudentAge,ColX,Coly,

    MAX(CASE WHEN Subject = 'English' THEN 'English' ELSE '' END) AS Subject1,

    MAX(CASE WHEN Subject = 'English' THEN Marks ELSE 0 END) AS Marks1,

    MAX(CASE WHEN Subject = 'English'...

  • RE: Finding Overlapping Start and End Time Values

    DECLARE @Employees TABLE (EmployeeId INT, LocationId INT, ActualStartDate DATETIME, ActualEndDate DATETIME)

    INSERT @Employees

    SELECT 20347,44,'2013-11-04 10:50:41.463','2013-11-04 10:53:03.953'

    UNION ALL

    SELECT 20347,44,'2013-11-06 13:39:03.733','2013-11-06 13:43:00.863'

    UNION ALL

    SELECT 20347,44,'2013-11-06 14:42:03.697','2013-11-06 14:46:00.863'

    UNION ALL

    SELECT 23658,80,'2013-11-01 11:18:08.767','2013-11-01 11:26:45.523'

    UNION ALL

    SELECT 23658,80,'2013-11-01 13:18:10.053','2013-11-01...

  • RE: Collect data from multiple rows into one row.

    select DISTINCT 'ID#'+CAST(ID_comment as NVARCHAR(100))+': "'+comments+'"-->'+'"'+comments+

    STUFF((

    SELECT DISTINCT ', '+R.name_code

    from flag F1

    INNER JOIN comments C1

    ON F1.comment_id = C.id_comment

    INNER JOIN register R

    ON F1.id_reg = R.id_reg

    where C1.id_comment = C1.id_comment

    FOR XML PATH('')

    ),1,1,'')+'"'

    from...

  • RE: Pivot

    Try to use dynamic pivot, this may help you,

    DROP TABLE #t1

    CREATE TABLE #t1

    (

    EmpID INT,

    [Height] NVARCHAR(100),

    [Weight] NVARCHAR(100),

    [Attitude] NVARCHAR(100),

    [Build] NVARCHAR(100),

    [DateID] INT

    )

    INSERT INTO #t1

    VALUES(1, '5.2', '65', 'Cool', 'Good', 1),(1, '5.2', '55', 'Cool',...

  • RE: Need help to split Data

    Try with Charindex

    DECLARE @StartTime VARCHAR(MAX),@X XML

    SELECT @StartTime = '7:00 AM

    12:30 PM'

    DECLARE @tbl TABLE

    (

    ID INT

    )

    INSERT INTO @tbl

    SELECT TOP 100 ROW_NUMBER() OVER(Order by s.object_id)

    from sys.objects s , sys.objects si

    select LTRIM(SUBSTRING(@StartTime,ID,CHARINDEX(CHAR(13),@StartTime+CHAR(13),ID))) from...

  • RE: date between in procedure

    You can make them parameter

    alter procdure date

    @Fromdate varchar(10),

    @todate varchar(10)

    AS

    --declare @Fromdate varchar(10)

    --declare @todate varchar(10)

    as begin

    select * from master

    where convert(varchar(10),@Fromdate,121) between CONVERT(varchar(10),@Todate,121) and CONVERT(varchar(10),rr.Original_Date,121)

    end

  • RE: Help Making a Query- URGENT

    Just In case you want to use CTE

    DECLARE @tbl TABLE

    (

    RatingID INT,

    Parameter_Order INT,

    ProjectKey INT,

    Comments NVARCHAR(MAX)

    )

    INSERT INTO @tbl

    SELECT 792 , ...

  • RE: Query For Lower Case f

    Can you check the below code, you can only update which are in Lower case.

    DECLARE @tblName TABLE

    (

    NAME VARCHAR(100),

    Action CHAR(1)

    )

    INSERT INTO @tblName

    SELECT '090909f','N'

    UNION ALL

    SELECT '090909F','N'

    Update @tblName SET name = UPPER(name),Action...

  • RE: Remove the first two characters in a column value if they meet a certain condition

    DECLARE @tbl TABLE

    (

    ID INT IDENTITY(1,1),

    SomeData VARCHAR(100)

    )

    INSERT INTO @tbl SELECT 'NA11345'

    INSERT INTO @tbl SELECT 'NA113456'

    INSERT INTO @tbl SELECT 'RA11345'

    UPDATE @tbl SET SomeData = SUBSTRING(SomeData,CHARINDEX('NA',SomeData)+2,LEN(SomeData))

    WHERE CHARINDEX('NA',SomeData) = 1

    select * from @tbl

  • RE: days into completed weeks only

    Please check if this can help you!!!

    select CAST(20.0/7 AS INT) + CASE WHEN (20%7) > 3 THEN 1 ELSE 0 END

  • RE: UNION TWO TABLES WITH ONLY ONE COLUMN IN COMMON

    Hey Santa,

    Can you please validate the below code

    SELECT Path,FolderName,FolderSize,FileName,FileSize

    FROM

    (

    SELECT PATH,FolderName,FolderSize,'' AS FileName,'' AS FileSize, 1 AS ID FROM @Folders

    UNION

    select PATH,'' AS FolderName,'' as FolderSize,FileName, FileSize,2 AS ID from @Files

    )E

    ORDER BY...

  • RE: Running Values ( Cummulative)

    Farooq,

    Can you please verify the below code. Looks better performance.

    DECLARE @tbl TABLE (ID int identity(1,1),dt DATETIME,program VARCHAR(100),Value INT,RunningTotal INT)

    INSERT INTO @tbl(dt,program,Value)

    SELECT '1/1/2012','Actual', 5

    UNION ALL SELECT '1/2/2012','Actual', 5

    UNION ALL...

  • RE: Running Values ( Cummulative)

    Hi ,

    Can you please try the below logic

    DECLARE @tbl TABLE (dt DATETIME,program VARCHAR(100),Value INT,RunningTotal INT)

    INSERT INTO @tbl(dt,program,Value)

    SELECT '1/1/2012','Actual', 5

    UNION ALL SELECT '1/2/2012','Actual', 5

    UNION ALL SELECT '1/3/2012','Actual', 1

    UNION...

  • RE: Ensure Table Has Only 1 Row

    onclick:if_IFCode('DECLARE @tbl TABLE

    (

    ID SMALLINT IDENTITY(-32768,-1),

    NAME VARCHAR(100)

    )

    INSERT INTO @tbl

    SELECT 'mitesh'

    select * from @tbl

    INSERT INTO @tbl

    SELECT 'mitesh'

    select * from @tbl');

  • RE: Compare 2 datasets and output delta in one TSQL statement

    --Compareandinsertdeltaintotable,inonesqlstatement

    Insert into #cmpAB

    ([EmpNr_a],[EmpNr_b],

    [Name_a],[Name_b],

    [HireDT_a],[HireDT_b],

    [FireDT_a],[FireDT_b]

    )

    SELECT a.[EmpNr],b.[EmpNr],a.[Name] , b.[Name],

    a.[HireDT] , b.[HireDT] , a.[FireDT] , b.[FireDT]

    FROM #tblA a INNER JOIN #tblB b

    ON a.[EmpNr] = b.[EmpNr]

    WHERE( a.[Name] <> b.[Name] OR a.[HireDT] <>...

Viewing 15 posts - 31 through 45 (of 89 total)