Forum Replies Created

Viewing 15 posts - 1,381 through 1,395 (of 1,417 total)

  • RE: While Loop

    Maybe you are trying to do something like:

    DECLARE @t TABLE

    -- or create a temp table

    (

     Policy_ProductId int not null primary key

     ,RowNum int identity not null )

    INSERT @t (Policy_ProductId)

    SELECT Policy_ProductId

    FROM Policy_Product

    INSERT INTO...

  • RE: Query returning data by date range

    David,

    WOW!

    It took me 15 minutes to understand what you did. It is a lot more efficient than my approach.

    All methods with their percentage of batch cost are below:

    declare @t table

    (

     tDate...

  • RE: Query returning data by date range

    Take the query:

    select T.tDate as DateFrom

     ,isnull

     (

      (select min(tdate)

      from @t T1

      where T1.price <> T.price

       and T1.tdate > T.tdate) - 1

     , D.MaxTDate) as DateTo

     ,T.price

    from @t T cross join

     (

      select min(T5.tdate),...

  • RE: Query returning data by date range

    The select statements are only test data. You will have to adapt the query so it works on your table.

     

  • RE: Query returning data by date range

    This is more efficient:

    select T.tDate as DateFrom

     ,isnull

     (

      (select min(tdate)

      from @t T1

      where T1.price <> T.price

       and T1.tdate > T.tdate) - 1

     , D.MaxTDate) as DateTo

     ,T.price

    from @t T cross join

     (

      select min(T5.tdate),...

  • RE: question about joins

    Try something like:

    select *

    from dbo.Companies C

     join dbo.Contacts E on C.companyId = E.companyId

    where E.contactId = ( select min(E1.contactId)

     from dbo.Contacts E1

     where E1.companyID = C.companyID)

     

  • RE: Query returning data by date range

    There is probably a better way, but this seems to work.

    declare @t table

    (

     tDate datetime not null primary key

     ,price int not null

    )

    insert @t

    select '20070101', 100 union all

    select '20070102', 100 union all

    select...

  • RE: Need help with INSERT statement with sub-query

    try:

     INSERT INTO my_table (comments,

                                    sr_status,

                                    sr_notes_count,

                                    sr_activity_count,

                                    last_updated_dt)

     SELECT 'some input comments',

                 (SELECT max(status) FROM my_table_2 WHERE id = 123),

                 (SELECT count(*) FROM my_table_3 WHERE id = 123),

                 (SELECT count(*) FROM...

  • RE: Need help finding stop time

    PW's approach is more efficient.

    --test data

    declare @t table

    (

     tName varchar(20) not null

     ,Event varchar(20) not null

     ,tTime datetime not null

    )

    -- 7.34% of cost

    insert @t

    select 'Name1', 'Start', convert(datetime, '8/16/06 8:00 AM', 0) union all

    select...

  • RE: Need help finding stop time

    --test data

    declare @t table

    (

     tName varchar(20) not null

     ,Event varchar(20) not null

     ,tTime datetime not null)

    insert @t

    select 'Name1', 'Start', convert(datetime, '8/16/06 8:00 AM', 0) union all

    select 'Name2', 'Start', convert(datetime, '8/16/06 8:15 AM', 0)...

  • RE: Which master db extended stored procedures used in app. db

    Run the profiler on the bits of the application which do not work and see what is called just before they fail.

     

  • RE: Finding a value within a value using a like join query

    Your query looks like it should work. You could simplfy it by trying something like:

    SELECT A.t_Code

    FROM C_CODES A

     LEFT JOIN Stories S ON S.story_dt BETWEEN '20060810 09:00' AND '20060810 10:00'

        AND ' '...

  • RE: shrinking the log file

    Try:

    alter database abcd

    set recovery simple

    use abcd

    go

    dbcc shrinkfile(abcd_log, 200)

    -- if originally in full recovery, reset

    alter database abcd

    set recovery full

    You will need to do a full backup afterwards.

     

  • RE: compared two table with

    Be careful with nulls but try something like:

    select *

    from dbo.Employees E

    where not exists (select *

      from dbo.ModuleLog L

      where L.EmployeeName = E.EmployeeName

       and L.DOB = E.DOB)

    or

    select E.*

    from dbo.Employees E

     left join dbo.ModuleLog L on...

  • RE: Param to pass to Oracle sp_ and sp_ to ret 1 or 0.

    I have never called an Oracle SP from T-SQL but you could try passing @status as an output parameter.

    eg exec DEV..SYSADM.update_procedure @Username,@status OUTPUT

     

Viewing 15 posts - 1,381 through 1,395 (of 1,417 total)