Forum Replies Created

Viewing 15 posts - 586 through 600 (of 2,007 total)

  • RE: any better way of doing this Query

    Not sure if this is any better, but here's one way: -

    SELECT

    a.id1, MAX(b.d1) AS description,

    a.id2, MAX(b.d2) AS description,

    a.id3, MAX(b.d3) AS description,

    a.id4, MAX(b.d4) AS description

    FROM Table1 a

    CROSS APPLY (SELECT

    ...

  • RE: how long it takes to retrieve top 10000 records

    ChrisM@Work (7/25/2012)


    Phil Parkin (7/25/2012)


    ChrisM@Work (7/25/2012)


    This looks very much like a homework question, in which case Anthony's reply is a good place to start.

    Don't forget that TOP is meaningless without...

  • RE: Get running total in the following query

    beeramgopi (7/25/2012)


    DECLARE @CumCredit TABLE

    (RowId INT, CustomerId INT, TransId INT, Pts INT)

    INSERT INTO @CumCredit (Rowid, CustomerID, TransId, pts)

    select 1,123,121,10

    union

    select 2,123,131,20

    union

    select 3,123,141,15

    select * from @CumCredit

    select a.*, (select sum(Pts) from @CumCredit where...

  • RE: View rows into columns

    Jeff Moden (7/6/2012)


    Cadavre (7/6/2012)


    Or, if we know that the "Column1" is unique we could do a subquery like this: -

    SELECT MAX(CASE WHEN RowNum % 3 = 0 THEN Column1 ELSE...

  • RE: View rows into columns

    Jeff Moden (7/6/2012)


    Here we go. This will do the trick in SQL Server 2000.

    --===== Conditionally drop the test table to make reruns in SSMS easier.

    ...

  • RE: search a string that contain 6 or 7 characters but no spaces

    David McKinney (7/6/2012)


    Thanks....I was puzzled why you introduced underscores into the mix. Would [a-z0-9] not be more appropriate (more restrictive) e.g. wouldn't allow funny characters.

    Yes, laziness from me 😉

    Technically,...

  • RE: search a string that contain 6 or 7 characters but no spaces

    Sure. How's this?

    SELECT pk, pcode

    FROM postcode

    CROSS APPLY (SELECT REPLACE(pcode COLLATE Latin1_General_BIN2,' ','')) b(fixedPcode)

    /*---------------------------------*UK Postcodes are arranged like this: -

    SortingOfficeCode+Space+LocalCode

    e.g. SK13 8LY or M1 1AA

    The LocalCode is always 3 characters...

  • RE: search a string that contain 6 or 7 characters but no spaces

    David McKinney (7/6/2012)


    Cadavre (7/6/2012)[hrActually, this would probably be more accurate: -

    SELECT pk, pcode

    FROM postcode

    CROSS APPLY (SELECT REPLACE(pcode COLLATE Latin1_General_BIN2,' ','')) b(fixedPcode)

    WHERE fixedPcode LIKE '[A-Z][A-Z0-9][0-9][A-Z][A-Z]'

    OR fixedPcode LIKE '[A-Z][A-Z0-9]_[0-9][A-Z][A-Z]'

    OR fixedPcode LIKE '[A-Z][A-Z0-9]__[0-9][A-Z][A-Z]'

    Depends...

  • RE: Need help with difficult Dynamic SQL query

    zxxz (7/5/2012)


    Sorry again, re-updating the original post. 🙂 I apologize in advance for any mistakes, but I don't think there are any.

    Corrected your DDL: -

    --===== If the test tables already...

  • RE: search a string that contain 6 or 7 characters but no spaces

    David McKinney (7/6/2012)


    consider also something like the following:

    x LIKE '[a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9]'

    or x LIKE '[a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9]'

    Actually, this would probably be more accurate: -

    SELECT pk, pcode

    FROM postcode

    CROSS APPLY (SELECT REPLACE(pcode COLLATE Latin1_General_BIN2,' ',''))...

  • RE: rolling 1 year period - but for completed weeks only

    More information please!! 😀

    To get the previous Sunday, you could do something like this: -

    DECLARE @date AS DATETIME = '2012-07-05 00:00:00.000';

    SELECT DATEADD(WEEK, DATEDIFF(WEEK, '2012-01-08', @date), '2012-01-08'); -- Previous Sunday,...

  • RE: search a string that contain 6 or 7 characters but no spaces

    WHERE LEN(pcode) IN (6,7) AND CHARINDEX(' ',pcode) = 0

    This is probably not a good way of determining validity of post codes though, there are a lot of rules (well, there...

  • RE: Returning all the month

    You haven't really given enough information to answer your question.

    Here's a random guess: -

    WITH t1(N) AS (SELECT N FROM (VALUES(1),(1))a(N)), -- 2 Rows

    t2(N) AS (SELECT 1 FROM t1 x, t1...

  • RE: ANSI JOIN VS Microsoft join

    chaithu559 (7/4/2012)


    Hi ,

    Let me take 2 examples :

    microsoft i am referring to : select * from emp ,dept where emp.deptno=dept.deptno

    So, is there...

  • RE: regex

    PATINDEX, LIKE and CHARINDEX can all be used to simulate regex.

    There's an article on CLR implementations here[/url], with further discussion in the discussion section (which I still intend to go...

Viewing 15 posts - 586 through 600 (of 2,007 total)