Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
I

i j russell

@i j russell
About
Posts
176
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • SQL Server table sizes.
    I i j russell

    If you have Reporting Services (SSRS) installed, you can right-click on a database in SSMS and select Reports -> Standard Reports -> Disk Usage by Table or Disk Usage by Top Tables.

    Database database sql-server com sysadmin help

  • SQL QUERY
    I i j russell

    Read the section on 'Concatenating values when the number of items is not known'.

    Database database sql-server sysadmin help question

  • SQL QUERY
    I i j russell

    https://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/[^]

    Database database sql-server sysadmin help question

  • What happens with auto-incremented value on rollback?
    I i j russell

    Identity (auto-increment) is not part of the transaction, so isn't rolled back. In your example, the ID for the next call would be 102.

    Database database question sql-server sysadmin

  • Book recommendation for learning SQL
    I i j russell

    If you are using SQL Server 2008 or later, I suggest you try T-SQL Fundamentals for Microsoft SQL Server by Itzik Ben-Gan.

    Database learning database question

  • SQL Table Grouping
    I i j russell

    Wow, I didn't think that anyone would still be using Sql Server 2000. It's five versions old and all support ends for it in April 2013 (see http://support.microsoft.com/lifecycle/?LN=en-us&x=14&y=13&c2=1044[^]).

    Database database help

  • SQL Table Grouping
    I i j russell

    Try this [not tested but it should work!]

    SELECT t1.PI,
    t1.JobID,
    t1.FormID,
    t1.ShiftID,
    t2.StartEvent,
    t2.SW,
    t2.SG,
    t3.EndEvent,
    t3.EG,
    t3.EW
    FROM
    (
    SELECT DISTINCT PI, JobID, FormID, ShiftID
    FROM [table]
    ) t1
    CROSS APPLY
    (
    SELECT TOP 1 StartEvent, SW, SG
    FROM [table]
    WHERE PI = t1.PI
    AND JobID = t1.JobID
    AND FormID = t1.FormID
    AND ShiftID = t1.ShiftID
    ORDER BY StartEvent ASC
    ) t2
    CROSS APPLY
    (
    SELECT TOP 1 EndEvent, EG, EW
    FROM [table]
    WHERE PI = t1.PI
    AND JobID = t1.JobID
    AND FormID = t1.FormID
    AND ShiftID = t1.ShiftID
    ORDER BY EndEvent DESC
    ) t3

    Database database help

  • Programming question
    I i j russell

    DO IT PROPERLY! Best practice is called that for a reason. If your Senior dev suggests otherwise, he is an idiot and doesn't deserve to be a professional developer.

    The Lounge question

  • LEFT OUTER JOIN not working
    I i j russell

    The WHERE clause was causing the LEFT OUTER JOIN to act as an INNER JOIN, hence you lost all of the records where there wasn't a match. Well done on finding the right way to do it and for showing others what you did!

    Database help question announcement

  • SQL Server : Query Cost (relative to the batch): 100%
    I i j russell

    You are misunderstanding what Query Cost is. If you run any single query, the cost will always be 100%. If you run multiple queries, the total cost of all of the queries in the batch added together will equal 100%. The value is used to compare the relative cost of each query in the batch as the message says.

    Database database question sql-server sysadmin

  • Parent-children Listing
    I i j russell

    CREATE TABLE #data
    (
    ID INT NOT NULL,
    PID INT NULL,
    VALUE VARCHAR(20) NOT NULL
    );

    INSERT INTO #data
    (ID, PID, VALUE)
    VALUES
    (1, NULL, 'node 1'),
    (4, 1, 'node 1/1'),
    (6, 4, 'node 1/1/1'),
    (5, 1, 'node 1/2'),
    (7, 1, 'node 1/3'),
    (2, NULL, 'node 2'),
    (3, NULL, 'node 3'),
    (8, 3, 'node 3/1');

    WITH MyCTE AS
    (
    SELECT ID, PID, VALUE, 0 AS [LEVEL]
    FROM #data
    WHERE PID IS NULL
    UNION ALL
    SELECT D.ID, D.PID, D.VALUE, [LEVEL] + 1
    FROM MyCTE M
    JOIN #data D
    ON D.PID = M.ID
    )
    SELECT ID, PID, VALUE, [LEVEL]
    FROM MyCTE;

    DROP TABLE #data;

    Database help

  • Flatten data (SQL)
    I i j russell

    CREATE TABLE #Person
    (
    ID INT NOT NULL,
    DOB DATE NOT NULL
    );

    CREATE TABLE #PersonName
    (
    ID INT NOT NULL,
    PID INT NOT NULL,
    FNAME VARCHAR(50) NOT NULL,
    MNAME VARCHAR(10) NULL,
    LNAME VARCHAR(50) NOT NULL,
    NAMETYPE CHAR(1) NOT NULL
    );

    INSERT INTO #Person
    (ID, DOB)
    VALUES
    (1, '2010-01-01'),
    (2, '2011-02-01'),
    (3, '2009-01-10');

    INSERT INTO #PersonName
    (ID, PID, FNAME, MNAME, LNAME, NAMETYPE)
    VALUES
    (1, 1, 'James', 'D', 'Doe', 'L'),
    (2, 1, 'Jim', NULL, 'Doe', 'C'),
    (3, 2, 'Martha', NULL, 'Stu', 'L'),
    (4, 3, 'William', 'H', 'Jefferson', 'L'),
    (5, 3, 'Bill', NULL, 'Jefferson', 'C');

    WITH L AS
    (
    SELECT *
    FROM #PersonName
    WHERE NAMETYPE = 'L'
    ),
    C AS
    (
    SELECT *
    FROM #PersonName
    WHERE NAMETYPE = 'C'
    )
    SELECT P.ID,
    L.FNAME AS FNAME_L,
    L.MNAME AS MNAME_L,
    L.LNAME AS LNAME_L,
    C.FNAME AS FNAME_C,
    C.MNAME AS MNAME_C,
    C.LNAME AS LNAME_C
    FROM #Person P
    LEFT JOIN L
    ON L.PID = P.ID
    LEFT JOIN C
    ON C.PID = P.ID;

    DROP TABLE #PersonName;
    DROP TABLE #Person;

    Database question database

  • keyword "dynamic" - real world applications?
    I i j russell

    Have a look at Massive[^], a data access class written by Rob Conery.

    C# csharp html com design algorithms

  • Breaking Up Classes
    I i j russell

    http://www.lostechies.com/content/pablo_ebook.aspx[^]

    C# question

  • Bringing in a New Table to Refresh an Existing One; Record Counts are Different; How do I say "Gimme the discrepant records?"
    I i j russell

    Use FULL OUTER JOIN.

    CREATE TABLE #first
    (
    Id INT NOT NULL,
    Name VARCHAR(10) NOT NULL
    );

    CREATE TABLE #second
    (
    Id INT NOT NULL,
    Name VARCHAR(10) NOT NULL
    );

    INSERT INTO #first (Id, Name) VALUES (1, 'One');
    INSERT INTO #first (Id, Name) VALUES (2, 'Two');
    INSERT INTO #first (Id, Name) VALUES (3, 'Three');
    INSERT INTO #first (Id, Name) VALUES (9, 'Nine');

    INSERT INTO #second (Id, Name) VALUES (2, 'Two');
    INSERT INTO #second (Id, Name) VALUES (3, 'Three');
    INSERT INTO #second (Id, Name) VALUES (5, 'Five');
    INSERT INTO #second (Id, Name) VALUES (7, 'Seven');

    SELECT f.Id AS fid,
    f.Name AS fname,
    s.Id AS [sid],
    s.Name AS sname
    FROM #first f
    FULL OUTER JOIN #second s
    ON s.Id = f.Id
    WHERE s.Id IS NULL OR f.Id IS NULL

    DROP TABLE #first;
    DROP TABLE #second;

    Database question database sysadmin

  • My talk
    I i j russell

    Yes, I go most months to Coventry and Birmingham and occasionally to Cambridge, Oxford and Hereford. Ian

    The Lounge beta-testing code-review

  • My talk
    I i j russell

    Enjoyed the nugget last night. If you were nervous, it didn't really show. It was almost as if the 'mistakes' were deliberate to show how if you follow the instructions, the thing works!

    The Lounge beta-testing code-review

  • Field ordering in a table
    I i j russell

    Blog post by Kimberly Tripp

    Database tutorial question

  • What is the best way to track 'database' modifications?
    I i j russell

    If you are using Sql Server 2005 or above, you should look at DDL Triggers for capturing changes to the database structure. http://www.simple-talk.com/sql/t-sql-programming/sql-server-2005-ddl-trigger-workbench/[^]

    Database database question oracle help

  • SQL n00b looking for study resources!
    I i j russell

    Buy a copy of Sql Server 2008 T-SQL Fundamentals by Itzik Ben-Gan published by Microsoft; It will give you a thorough grounding in T-SQL. I can't recommend this book highly enough.

    Database sysadmin database help workspace
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups