Forum Replies Created

Viewing 15 posts - 1 through 15 (of 16 total)

  • RE: TOP 1 for each employee

    You could use CTE (Common table expressions) and ROW_NUMBER().

    I could use Derived Table instead CTE.

  • RE: The new Analytic functions in SQL Server 2012

    I see first_value and last_value function, but do not see second or third value function!

    How can I write for example second_value() function by using analytical window function?

  • RE: No Wildcards Characters

    ScottPletcher (1/24/2013)


    declare @search_pattern_should_be varchar(100)

    set @search_pattern_should_be = '%[[][[][%] SQL Server [%]]]%'

    --example

    select case when @string like '%[[][[][%] SQL Server [%]]]%'

    then'Matched' else...

  • RE: No Wildcards Characters

    Thanks,

    So the second one can be more simpler like this:

    LIKE '$[$[$% SQL Server $%]]' ESCAPE '$'

  • RE: No Wildcards Characters

    It's easy no need to sample data, I want an alternative LIKE for this without ESCAPE.

    like '%?[?[?% SQL Server ?%?]?]%' ESCAPE '?'

    I wrote this code, but that is not correct:

    like...

  • RE: Divide N object to N person

    I forgot to say thank you.

    The generalizability is necessary.

    I get 324 unique, fruity combos!

    Because your solution return duplicate combos! you need to filter them.

    For example see ComboNo IN (1, 11,...

  • RE: Divide N object to N person

    I get 324 unique, fruity combos!

    I think your result is not correct. Run you query with following sample data:

    INSERT INTO #n_objects

    SELECT 1, 'Apple' UNION ALL

    SELECT 2, 'Orange' UNION ALL...

  • RE: String REPLACEMENT Question

    The recursive CTE may not scale well as the length of the strings increase. Both sets of options really need to be tested to determine which is better solution.

    My...

  • RE: String REPLACEMENT Question

    declare @t table(id int, string varchar(500))

    insert @t values (1,'abcABC,0123456789~!@'),(2,'123abcdefghijklmnopqrstuvwzyz');

    with cte1 as

    (

    select id,

    0 nbr,

    cast(string as varchar(500))...

  • RE: String REPLACEMENT Question

    declare @t table(id int, string varchar(500))

    insert @t values (1,'abc0123456789'),(2,'123abcdefghijklmnopqrstuvwzyz');

    with cte as

    (

    select id,1 nbr, cast(string as varchar(500)) string

    from @t

    union all

    ...

  • RE: Insert Into #temp table

    where RecordId = 3212

    and

    (

    '2012' > ANY

    (select AlphaNumeric2 union all

    select AlphaNumeric5 union all

    ...

  • RE: Insert Into #temp table

    Thank you Sean Lange.

    😀

    select m.RecordId,m.NumberForSearch into #dump

    from table1 m join table2 a on m.RecordId = a.RecordId

    cross apply (

    select 1

    from (

    values(a.AlphaNumeric2),

    (a.AlphaNumeric5),

    ...

  • RE: Insert Into #temp table

    where RecordId = 3212

    and not(replace(AlphaNumeric2 + AlphaNumeric5 + AlphaNumeric7 + AlphaNumeric9, '2012', '') = '')

  • RE: Insert Into #temp table

    Only in some case also:

    ;with cte as

    (

    select m.RecordId,m.NumberForSearch,

    a.AlphaNumeric2,a.AlphaNumeric5,a.AlphaNumeric7,a.AlphaNumeric9

    from table1 m join table2 a on m.RecordId = a.RecordId

    where RecordId = 3212

    )

    select RecordId,NumberForSearch into...

  • RE: Insert Into #temp table

    What about this:

    where RecordId = 3212

    and 1 in

    (select case when AlphaNumeric2 = '2012' then 0 else 1 end union

    select case when AlphaNumeric5 =...

Viewing 15 posts - 1 through 15 (of 16 total)