Forum Replies Created

Viewing 15 posts - 301 through 315 (of 355 total)

  • RE: Help with select

    SELECT *

    FROM [MyTable]

    WHERE ((CASE CalcLT

    WHEN 1 THEN Col1

    WHEN 2 THEN Col2

    WHEN 3 THEN Col3

    WHEN 4 THEN Col4

    END) < 0)

  • RE: Splitting a date range into multiple rows.Is a loop/cursor needed?

    Looks OK to me.

    Presumably the number of consecutive days that an employee can take off is never going to exceed 100, so you won't run into problems with your synthetically...

  • RE: Cursors

    Try specifying the length of the varchar local variables to match the length of the columns in your table schemas.

    DECLARE

    @newEmpID varchar,

    @firstname varchar,

    @lastname varchar

  • RE: Cursors

    The order of the columns in the SELECT statement used to declare your cursor

    Select newEmpID, firstname, lastname FROM ausersOmega

    should match up with the order of variables in your FETCH statement:

    FETCH...

  • RE: Cursors

    Why are you using a cursor? it can be done with a single UPDATE statement.

    UPDATE U SET employee_id = NU.newEmpID

    FROM users U

    JOIN ausersOmega NU ON (U.firstname = NU.firstname AND U.lastname...

  • RE: Splitting a date range into multiple rows.Is a loop/cursor needed?

    Does this do what you want?

    The first SELECT includes a row for each single-day row in the source data regardless of the weekday.

    The second SELECT in the UNION uses a...

  • RE: SQL Group Multiple Columns

    OK, will this work?

    I've assumed that the ParentId column is NULL if the row is the original entry for that quote

    SELECT R.QuoteId, R.ReferenceNumber, R.CustomerName, R.TotalAmount,

    SaleType = CASE WHEN EXISTS (

    SELECT...

  • RE: SQL Group Multiple Columns

    I'm writing a query for a receipt table. Whenever a return is processed, the current system inserts another record with the exact same information except with a negative amount and...

  • RE: SQL Group Multiple Columns

    You don't state what your total amout column name is, but assuming it is TotalAmount then does the following work?

    SELECT R.QuoteId,

    R.ReferenceNumber,

    R.CustomerName,

    MAX(R.TotalAmount),

    CASE WHEN COUNT(*) > 1 THEN 'Reverted'...

  • RE: Checking for last day of the month?

    Here's another way of calculating the first and last days of the current month

    SELECT FirstOfMonth = DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0),

    LastOfMonth = DATEADD(month, DATEDIFF(month, 0, GETDATE()) + 1, -1)

  • RE: Convert matrix style table to usable result set

    In my solution I've used the following table schema, although using different column names will not make any difference.

    CREATE TABLE dbo.Matrix (

    RKey varchar(10) NOT NULL,

    ColVal1 char(1) NULL,

    ColVal2 char(1) NULL,

    ColVal3 char(1)...

  • RE: Selectecting records from the table falling in provided date range

    If OP wants to select records where the date range in the table row overlaps the date range defined in the input parameters, then Vladan is right, and rtomkins' extra...

  • RE: Splitting a date range into multiple rows.Is a loop/cursor needed?

    What about national holidays? Should they be treated like Saturdays and Sundays? If so, you will need to use a calendar table.

    A calendar table might be the best option...

  • RE: Combing columns/filling in parameters

    You haven't provided your full table schema, so in the following I've assumed a table named XmlTemplate as follows. I've assumed there is primary key field (id) on this table...

  • RE: Splitting a date range into multiple rows.Is a loop/cursor needed?

    Does this query give you what you need?

    It appears to replicate the output from your script.

    A couple of points to note:

    1) I've used floating point division to calculate the...

Viewing 15 posts - 301 through 315 (of 355 total)