Forum Replies Created

Viewing 15 posts - 1,216 through 1,230 (of 1,496 total)

  • RE: parameter to derived table

    Derived tables can be regarded as inline views so you cannot pass parameters. Something like the following should work:

    SELECT T.col1, T.colDate, T.col3

    FROM Table2 T

        JOIN (

                SELECT T2.col1, MAX(T2.colDate) AS maxDate

                FROM Table1...

  • RE: Handling a malformed CSV file

    The quick method of doing this from the command prompt is:

    echo.>>YourFile.csv

    You could put this in a batch file.

     

  • RE: Return next available product value

    Maybe:

    SELECT MIN(ProductCode)

    FROM YourTable

    WHERE ProductCode >= '12'

     

  • RE: Is there a way to output table variable from a dynamice SQL?

    If you need dynamic SQL, you can insert the results into a temp table. eg:

    CREATE TABLE #Multi

    (

        Attribute varchar(100) NOT NULL

    )

    INSERT INTO #Multi

    EXEC ('SELECT attribute FROM dbo.Staging WHERE CHARINDEX('','', attribute) >...

  • RE: Is there a way to output table variable from a dynamice SQL?

    A table variable cannot be used as a parameter. (Also, it seems to be defined as @tMulti not @Multi.)

    I see no point with dynamic SQL here. Why not just:

    DECLARE @Multi...

  • RE: Creating a calculated boolean colum using CharIndex results

    Peter,

    Sorry for not being clear.

    I was refering to Gary's charindex > 0 test.

  • RE: Creating a calculated boolean colum using CharIndex results

    Why do you want to do a comparison?

    DECLARE @b-2 bit

    SET @b-2 = CHARINDEX('c', 'abc')

    SELECT @b-2

    SET @b-2 = CHARINDEX('d', 'abc')

    SELECT @b-2

  • RE: How to do a recursive join ?

    You may need to make sure that parentID <> ChildID in the reference table.

    If you have loops in the data I would suggest you get rid of them using iteration.

     

     

  • RE: CAST varchar to int

    SELECT

        CAST(LEFT(DataRow, CHARINDEX('A', DataRow) - 1) AS int) AS QuestionNo

        ,CAST(SUBSTRING(DataRow, CHARINDEX('A', DataRow) + 1, 8000) AS bigint) AS AnswerNo

    FROM (

            SELECT '02245A555115555155'

        ) AS YourTable (DataRow)

     

  • RE: How to do a recursive join ?

    Your basic problem is that you need to carry the current parent value through the recursion.

    Also, you would probably find it easier if the Reference table was structured better by containing...

  • RE: identifying a table for subsequent query

    -- Option 1

    -- Dynamic SQL

    DECLARE @SQLString nvarchar(4000)

        ,@Count int

    SET @SQLString = N'SELECT @pCount = COUNT(whatever) FROM ' + @ActiveTable

    EXEC sp_executesql @SQLString, N'@pCount int OUTPUT', @Count OUTPUT

    SELECT @Count

    -- Option 2

    -- If the...

  • RE: Syntax update derived tables

    or:

    UPDATE Membership

    SET kMembStatusCode = 2

        ,StatusDate = GETDATE()

    WHERE EXISTS (

            SELECT *

            FROM OrgsToAppend A

            WHERE Membership.OrganisationID = A.OrganisationID

                AND A.Member = 1

        )

        AND kOtherClassDescID = @IDTo

        AND MembStatusCode = @Term

  • RE: Syntax update derived tables

    Try:

    UPDATE B

    SET kMembStatusCode = 2

        ,StatusDate = GETDATE()

    FROM Membership B

        JOIN OrgsToAppend A

            ON B.OrganisationID = A.OrganisationID

    WHERE A.Member = 1

        AND B.kOtherClassDescID = @IDTo

        AND B.MembStatusCode = @Term

     

  • RE: Unique data in report

    Maybe:

    SELECT T1.*

    FROM YourTable T1

        JOIN (

            SELECT T2.TagName, MAX(T2.[Date]) AS [Date]

            FROM YourTable T2

            GROUP BY T2.TagName

        ) D ON T1.TagName = D.TagName

                AND T1.[Date] = D.[Date]

    ORDER BY T1.[Date] -- DESC

     

Viewing 15 posts - 1,216 through 1,230 (of 1,496 total)