Forum Replies Created

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

  • RE: need help

    Hi there,

    Here's the solution i came up with.. I hope it helps..:-)

    ;WITH cte AS

    (

    SELECTEmpId

    , StartDate

    , ISNULL(EndDate,GETDATE()) as EndDate

    , ROW_NUMBER() OVER (PARTITION BY Empid ORDER BY StartDate) rn

    FROM Duration d

    )

    SELECTa.EmpId

    ,MIN(a.StartDate) AS...

  • RE: “Distinct” column in SQL query results

    Hi there,

    I hope this helps..

    DECLARE @x TABLE (col1 INT, col2 VARCHAR(10))

    INSERT INTO @x

    SELECT 1,'0TY/OK' UNION ALL

    SELECT 1,'0TY/OK' UNION ALL

    SELECT 1,'0TY/OK' UNION ALL

    SELECT 1,'0TY/OK' UNION ALL

    SELECT 1,'0TY/OK' UNION ALL

    SELECT 2,'2KP/L'...

  • RE: How to change some of the columns in to rows

    Hi..

    This may produce your expected result.. I just added logic to concatenate the values from unpivoted table..

    DECLARE @table TABLE (Emp_Name VARCHAR(50),PHN INT, MOB INT, OTH INT)

    INSERT INTO @table

    SELECT 'Steve',223,456,895 UNION...

  • RE: Selecting "All" records where "All" is actually only partial records

    Hi Mac,

    I believe this has relation to your previous post.. 😀

    I created table mapping between users and groups here, so it can retrieve only the groups where a particular user...

  • RE: SQL JOINS

    Hi there,

    There's nothing wrong with your query.. Use DISTINCT keyword to eliminate the duplicate values..

    Syntax here:

    SELECT DISTINCT <column 1>, ... <column N>

    FROM <table>

    Just a side note, alias name is mostly...

  • RE: Chose Record List from a table based on two selections

    My apologies for my late reply..

    I used your sample data with additional AuditLevel column.. This will include '(All)' if @CheckAuditor = 0..

    DECLARE @AuditTypes TABLE (AuditTypeId INT, AuditType NVARCHAR(100), AuditLevel...

  • RE: Chose Record List from a table based on two selections

    The IDs are hard-coded in the solution that I have presented.. I agree with Scott that it would be more efficient and easier to maintain if separate table would be...

  • RE: How can I use union and for xml in one sql statement?

    I agree with Robert, use a derived table to combine the names before applying FOR XML PATH.. If you want the column to have an alias, you need to use...

  • RE: Chose Record List from a table based on two selections

    Hi again..

    You may eliminate cross join with correlated subquery, here's my other solution..

    SELECT AuditTypeId, AuditType

    FROM @AuditTypes at

    WHERE AuditTypeId = CASE WHEN @CheckAuditor = 0

    THEN AuditTypeID

    ELSE

    (SELECT TOP(1) AuditTypeId FROM...

  • RE: Chose Record List from a table based on two selections

    Hi there,

    I'm just trying to help.. You may use correlated subquery to filter the result depending on the parameter passed.. Here's my solution:

    DECLARE @AuditTypes TABLE (AuditTypeId INT, AuditType NVARCHAR(100))

    DECLARE...

  • RE: INSERT INTO SELECT WITH ORDER BY

    Hi there,

    The result is also sorted by V1 and V2 in ascending order since that is the order when you inserted those records into @AAAATABLE.. Running your query produces this...

  • RE: adding referential integrity

    Hi there,

    Just wanna help you.. I think you need to make DependentNo column from Table2 a primary key to ensure referential integrity..

    This is my proposed table design..

    CREATE TABLE Table1

    (

    UserId INT...

  • RE: Different behaviour of query on 64 bit and 32 bit

    Hi there,

    I'm running a 32-bit version of SQL Server.. Your query also produces the same error on my machine.. But, without ORDER BY clause, the query runs fine.. I think...

  • RE: Need help....

    Hi there,

    This query might produce your expected result:

    SELECT vc.case_sk, vc.case_number, vc.style, vle.computename AS PartyName, cpa.create_user_id, cpa.action_sk, cpa.action_date,

    cpa.action_date AS BeginDate, cpa.action_date AS EndDate, cpa.entity_sk, vle.legal_entity_sk

    FROM#vle AS vle

    JOIN#cpa AS...

  • RE: Help with a weird query

    Hi there,

    Does it mean there is at least 2 occurrences of same number in IdY? Ex: IdX=770001.. 770001 appears twice in IdY.. Sample code below:

    CREATE TABLE test

    (

    IdX INT,

    IdY INT,

    Sc INT,

    Va...

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