Forum Replies Created

Viewing 15 posts - 1,441 through 1,455 (of 1,489 total)

  • RE: How to tell if a character exists

    select *

    from YourTable

    where ShipToNum not like '%[^0-9]%'

  • RE: prevent a delete - cross-database

    There are no BEFORE Triggers so you have to use an INSTEAD OF trigger or a SP.

     

  • RE: Other Ways to Exclude Values

    Just noticed that you do not want AcctCode in addition to 'Payment Servi'.

    This may work:

    -- Do not have enough info to tell if distinct is needed

    select distinct PR.PrmLog_Acct_Code, PR.PrmLog_Customer_ID

    from dbo.PrmrLog...

  • RE: Other Ways to Exclude Values

    A quick perusal of your code suggests that the following may work.

    -- Do not have enough info to tell if distinct is needed

    select distinct PR.PrmLog_Acct_Code, PR.PrmLog_Customer_ID

    from dbo.PrmrLog PR

    where exists (select...

  • RE: T_SQL

    Replace @test-2 with [Description] as above.

    ps If you do need local variables, do not declare them in the parameter list.

    pps If possible, normalize the database.

  • RE: T_SQL

    If the position of the !'s is not fixed use the following, otherwise hardcode in the numbers.

    ALTER PROCEDURE dbo.spGetInks

    (@Company varchar(50), @Site varchar(50), @Zone varchar(50))

    AS

    SET NOCOUNT ON

    SELECT D.[Name]

     ,D.[Description]

     ,RTRIM(SUBSTRING(D.[Description], D.P1 + 1, D.P2...

  • RE: T-SQL against Sybase Database?

    Sybase uses a different dialect of T-SQL. There is some documentation at:

    http://manuals.sybase.com/onlinebooks/group-as/asg1250e/sqlug

     

     

  • RE: SQL Query Latest Tracking details

    I think you need to force the join order with something like:

    select T1.[Name], T1.tracking_number, T2.start_date, T3.first_name, T3.last_name

    from Table1 T1

     left join

     (

      Table2 T2

      join

      ( select T22.tracking_number, max(T22.start_date) as start_date

       from Table2 T22

       group by T22.tracking_number) D

      on...

  • RE: Pivot/Rotate Table

    I think this would be best done either in the middle tier or by using a cursor.

    If you have less than 1000 rows something like the following ghastly looking query...

  • RE: Unable to make this query run.. trying to build query by concatenating strings

    Try sp_executesql with output parameters. Something like:

    declare @EmployeeNo int, @AccessLevelID int, @err int

    set @queryString = 'select @EmployeeNo = b.employee_no, @AccessLevelID = a.Access_Seq from '

      + @dbName + '..employee a, '...

  • RE: TSQL PRoblm

    -- Test data

    declare @t table

    (

     refNo char(5) not null primary key

    )

    insert @t

    select 'ABC-0' union all

    select 'ABC-1' union all

    select 'XYZ-0' union all

    select 'XYZ-1' union all

    select 'XYZ-2' union all

    select 'PQR-0' union all

    select 'MNO-0'...

  • 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.

     

Viewing 15 posts - 1,441 through 1,455 (of 1,489 total)