Forum Replies Created

Viewing 15 posts - 1,456 through 1,470 (of 1,489 total)

  • 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

     

  • RE: Id of the last inserted

    No problems - I know the feeling.

    At the time I thought Erland Sommarskog's post succinctly summed up the issues. I just re-posted it as I have found it to be...

  • RE: Id of the last inserted

    The original question was about identities so I answered it.

    I agree that you have to think very carefully before using identity as a Primary Key but quite often one has...

  • RE: Left of a comma

    declare @t table(namestr varchar(50) not null)

    insert @t

    select 'Aardvark, Archie (1)' union all

    select 'Baboon, Bob (2)' union all

    select 'Chimp, Charlie (3)'

    select ltrim(rtrim(left(namestr, commaPos - 1))) as LastName

     ,ltrim(rtrim(substring(namestr, commaPos + 1, bracket1Pos...

  • RE: Id of the last inserted

    Use SCOPE_IDENTITY() after each insert. Something like:

    declare @LastID int

    insert table1(...) select ...

    set @LastID = SCOPE_IDENTITY()

    insert table2(Table1ID, ...) select @LastID, ...

    set @LastID = SCOPE_IDENTITY()

    insert table3(Table2ID, ...) select @LastID, ...

     

     

Viewing 15 posts - 1,456 through 1,470 (of 1,489 total)