Forum Replies Created

Viewing 15 posts - 1,666 through 1,680 (of 2,007 total)

  • RE: Cursor killing my server

    Convert the cursor into a set-based solution.

    With the current information from your post, that's the best answer I can give. If you want a better answer, I'd need you to...

  • RE: To select one month old record

    Bear in mind that unlike Ken's solution, this solution will always get the data from the first of last month to the first of this month, regardless of the day...

  • RE: To select one month old record

    SELECT *

    FROM YourTable

    --Grabs data between the 1st of last month and the 1st of this month

    WHERE date1 >= DATEADD(MONTH,DATEDIFF(MONTH,0,GETDATE())-1,0),

    AND date1 < DATEADD(MONTH,DATEDIFF(MONTH,0,GETDATE()),0)

  • RE: Need Round Robin- For loop in T-SQL

    What you're talking about isn't a job for SQL. What are you actually trying to achieve?

    If you insist, you could do it in a few ways. One such would be...

  • RE: Query to join the table

    Those tables are awful. . . what is the purpose of this?

    --Test data, two simple tables since you didn't supply DDL

    DECLARE @table1 AS TABLE (col1 CHAR(5), col2 CHAR(2), col3 CHAR(3))

    INSERT...

  • RE: Help with CASE

    agh100 (5/5/2011)


    Well that was even better...

    Well, that depends 😉

    Best bet is to run some tests on your own data, or knock-up some test data to play with.

    Try this to get...

  • RE: Hierarchy using CTP & extra column for HasChildren?

    Speed is the name of the game, and I suspect that if you try this code on a tree with a couple of million nodes then you'll see it chew...

  • RE: Hierarchy using CTP & extra column for HasChildren?

    Off the top of my head: -

    DECLARE @sample AS TABLE (PersonID INT, Position NVARCHAR(50), ParentPersonID INT)

    -- Insert some sample data into the table based on the structure shown above

    INSERT INTO...

  • RE: Help with CASE

    An alternative to CASE: -

    --Build some test data since you didn't supply any

    DECLARE @blablabla AS TABLE (UnitCost MONEY, UnitPrice MONEY)

    INSERT INTO @blablabla

    SELECT 0, 1.50

    UNION ALL SELECT 1.12, 1.45

    UNION ALL SELECT...

  • RE: Table Data

    Steve Jones - SSC Editor (5/4/2011)


    There isn't a good way to figure out what's in tables. If I create a C0101 table, SQL Server has no idea what I store...

  • RE: Table Data

    Are you running SQL Server 2000? I assumed you're running 2008 since that is the forum you posted in.

  • RE: Table Data

    This script came from one of the many blogs that I read - sorry but I can't remember which one right now.

    WITH doc_db AS (

    SELECT Object_schema_name(objectid) AS object_schema,

    ...

  • RE: DATEADD FUNCTION

    No problem. Bear in mind that there may be faster ways to accomplish your task 😉

  • RE: DATEADD FUNCTION

    --First, lets build some test data, since you didn't supply any I've used a simple table

    DECLARE @table AS TABLE (mydate DATETIME)

    ;WITH testdata AS (

    SELECT...

  • RE: Select Random Row from a table

    Something like this?

    DECLARE @MaxValue INT, @MinValue INT

    SET @MaxValue = 500

    SET @MinValue = 1

    SELECT * FROM (SELECT columns, ROW_NUMBER() OVER (ORDER BY key ASC) AS rownumber

    ...

Viewing 15 posts - 1,666 through 1,680 (of 2,007 total)