Forum Replies Created

Viewing 15 posts - 1,081 through 1,095 (of 1,491 total)

  • RE: Create Parent Child Structrure from dataset

    The following is a set based solution but, as it involves a triangular join, a cursor will be quicker on large data sets. What constitutes a large data set will...

  • RE: dealing with calculations

    SELECT *

    &nbsp&nbsp&nbsp&nbsp,T.Depreciation +

    &nbsp&nbsp&nbsp&nbspCOALESCE

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT SUM(T1.Depreciation)

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspFROM YourTable T1

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHERE T1.[ID] < T.[ID]

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp)

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp, 0

    &nbsp&nbsp&nbsp&nbsp) AS AccummulativeDepreciation

    FROM YourTable T

  • RE: Parse Multiple Substrings Between 2 Characters

    -- *** Test Data ***

    DECLARE @t TABLE

    (

    &nbsp&nbsp&nbsp&nbspMeter varchar(20) NOT NULL

    &nbsp&nbsp&nbsp&nbsp,MeterDate datetime NOT NULL

    &nbsp&nbsp&nbsp&nbsp,Value int NOT NULL

    )

    INSERT INTO @t

    SELECT 'Meter_1', '20080101', 10 UNION ALL

    SELECT 'Meter_2', '20080101', 50 UNION ALL

    SELECT 'Meter_3', '20080101',...

  • RE: Evaluating rules from a table and applying them to data (in TSQL)

    Or, if you have very complicated and validated expressions (eg QTY needs to be SalesQTY), you could try dynamic SQL. eg:

    -- *** Test Data ***

    CREATE TABLE #Products

    (

    &nbsp&nbsp&nbsp&nbspProductID int NOT NULL

    &nbsp&nbsp&nbsp&nbsp,SalesValue...

  • RE: Where case statement

    I think you should try it or try 9 separate queries if MajorArea is the same for each row in the result set.

  • RE: Urgent help needed

    Try using CASE

    SELECT N.PersonID

    &nbsp&nbsp&nbsp&nbsp,MAX(CASE N.nameTypeID = 7780 THEN [Name] END) AS NameFirst

    &nbsp&nbsp&nbsp&nbsp,MAX(CASE N.nameTypeID = 7781 THEN [Name] END) AS NameMiddle

    &nbsp&nbsp&nbsp&nbsp,MAX(CASE N.nameTypeID = 7783 THEN [Name] END) AS NamePreferred

    &nbsp&nbsp&nbsp&nbsp,MAX(CASE N.nameTypeID =...

  • RE: Where case statement

    Maybe something like:

    WHERE EXISTS

    (

    &nbsp&nbsp&nbsp&nbspSELECT *

    &nbsp&nbsp&nbsp&nbspFROM

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT ManagingGroupID, 'tb_Core' FROM tb_CoreManGroup WHERE CoreID = @id

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspUNION ALL

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT ManagingGroupID, 'tb_Event' FROM tb_EventManGroup WHERE EventID = @id

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspUNION ALL

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT ManagingGroupID, 'tb_FocusGroup' FROM tb_FocusGroupManGroup WHERE FocusGroupID =...

  • RE: two or more row values in a single row

    In SQL2005, a CTE could be used.

    A temp table can be avoided, in SQL2000, by doing something horrible like:

    SELECT T1.[ID], T1.[NAME] AS Name1, T2.[NAME] AS Name2

    FROM YourTable T1

    &nbsp&nbsp&nbsp&nbspJOIN

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT T11.[ID], MIN(T11.SUB)...

  • RE: How to declare parameters inside "select"?

    I would be inclined to use a function. Something like:

    SET QUOTED_IDENTIFIER, ANSI_NULLS ON

    GO

    CREATE FUNCTION dbo.GetAssetNames

    (

    &nbsp&nbsp&nbsp&nbsp@policy_number varchar(20) -- or whatever the datatype of policy_number is.

    )

    RETURNS varchar(8000)

    AS

    BEGIN

    &nbsp&nbsp&nbsp&nbspDECLARE @AssetNames varchar(8000)

    &nbsp&nbsp&nbsp&nbspSET @AssetNames =...

  • RE: Row level lock

    Try using a transaction and UPDLOCK.

    Here is an outline - you will need to add error handling etc.

    DECLARE @NextInvoiceNumber int

    BEGIN TRANSACTION

    SET @NextInvoiceNumber =

    (

    &nbsp&nbsp&nbsp&nbspSELECT NextInvoiceNumber

    &nbsp&nbsp&nbsp&nbspFROM InvoiceNumbers WITH (UPDLOCK)

    &nbsp&nbsp&nbsp&nbspWHERE Company =...

  • RE: Problem in Query

    Try something like:

    SELECT *

    FROM ord1 H

    WHERE EXISTS

    (

    &nbsp&nbsp&nbsp&nbspSELECT NULL

    &nbsp&nbsp&nbsp&nbspFROM PRCR C

    &nbsp&nbsp&nbsp&nbspWHERE C.customer = H.customer

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND C.division = H.division

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND C.ack_by = 'P'

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND C.sku_upc <> 'N'

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND C.ovnd_key IN (H.ovnd_key, '')

    )

  • RE: CTE Query

    Maybe you could try variations on:

    SELECT T3.IDK, T3.C4

    FROM T3

    WHERE EXISTS

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT *

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspFROM T1

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHERE T1.C1 = T3.IDK

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND EXISTS

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT *

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspFROM SelField S

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHERE S.val = T1.C1

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp)

    &nbsp&nbsp&nbsp&nbsp)

    &nbsp&nbsp&nbsp&nbspAND EXISTS

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT T2.IDK

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspFROM T2

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHERE T2.IDK = T3.IDK

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspGROUP BY T2.IDK

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspHAVING...

  • RE: Unusual syntax

    I think these are the ODBC functions which TSQL seems to be able to process.

  • RE: CTE Query

    Get rid of the second WITH.

  • RE: Substring

    DECLARE @s varchar(255)

    SET @s = 'Mark_m_andrew_levey_caa12002'

    SELECT REVERSE(LEFT(REVERSE(@s), CHARINDEX('a', REVERSE(@s)) - 1))

Viewing 15 posts - 1,081 through 1,095 (of 1,491 total)