Forum Replies Created

Viewing 15 posts - 31 through 45 (of 53 total)

  • RE: conditional joins in select statement

    As Koen mentioned that is not possible in SQL and should explore the options he mentioned.

    Probably one more option if i understand your question correctly is to do a LEFT...

  • RE: Many to Many Recursive CTE

    Try the below code...

    DECLARE @TransactionComponents TABLE

    (

    pkTransactionComponent int IDENTITY(1,1) NOT NULL,

    pkTransactionID int NOT NULL,

    ComponentID int NULL

    )

    INSERT INTO @TransactionComponents(pkTransactionID, ComponentID)

    SELECT 1,5

    UNION SELECT 1,6

    UNION SELECT 1,7

    UNION SELECT 1,8

    UNION SELECT 1,9

    UNION SELECT 1,10

    UNION SELECT...

  • RE: Must declase Scaler Variable error on Multiselect parameter when I use IN statement in SP ?

    Duplicate post. Original thread available here

  • RE: Must Declare Scalar Variable Error with IN Clause ?

    Try below

    ALTER PROCEDURE [dbo].[..._count]

    @StartDate datetime,

    @EndDate datetime,

    @Costcenter varchar(3),

    @DiagnosisType varchar(100)

    AS

    SELECT .....

    --where (dbo.ClinicalType.Code in (@DiagnosisType))

    where CHARINDEX(LTRIM(RTRIM(dbo.ClinicalType.Code)),@DiagnosisType) > 0

  • RE: Difficulties to use sp_send_dbmail with @@SERVERNAME

    DECLARE @MailBody VARCHAR(500)

    SELECT @MailBody = 'My text for server ' + @@SERVERNAME

    EXEC MSDB..SP_Send_DBMail

    @Subject = 'my_subject',

    @Recipients = 'my_email_adresse',

    @Body = @MailBody,

    @Profile_name = 'my_profile'

  • RE: Time between range

    DECLARE @BetTime DATETIME

    SELECT @BetTime = CONVERT(DATETIME,'03:30:00')

    ;WITH ShiftTimes AS

    (

    SELECT 1 AS ShiftNo,CONVERT(DATETIME,'06:00:00') AS StartTime,

    CONVERT(DATETIME,'14:00:00') AS EndTime

    UNION

    SELECT 2,CONVERT(DATETIME,'14:00:00'),CONVERT(DATETIME,'22:00:00')

    UNION

    SELECT 3,CONVERT(DATETIME,'22:00:00'),CONVERT(DATETIME,'06:00:00')

    )

    SELECT TOP 1 * FROM ShiftTimes

    WHERE EndTime >= @BetTime

    ORDER BY EndTime

  • RE: Separate two Values

    If the data is always numbers then just convert the data-type to integer which will remove the leading zero's.

    SELECT CONVERT(INT,SUBSTRING(Oddvalue,1,charindex(' ',Oddvalue+' ',1)))

    FROM @OddRows

  • RE: Separate two Values

    Without the CASE statement

    DECLARE @OddRows TABLE

    (

    Oddvalue VARCHAR(50)

    )

    DECLARE @PerfectRows TABLE

    (

    Oddvalue VARCHAR(50)

    )

    INSERT INTO @OddRows

    SELECT '002849617 00009' UNION ALL

    SELECT '002960330 00009' UNION ALL

    SELECT '003181242 00009' UNION ALL

    SELECT '003701140 00009' UNION ALL

    SELECT '003789064 00009'...

  • RE: SQL case when statement( without hardcode values)

    This might not be the most elegant way but give it a try

    SELECT StartDate =

    CASE WHEN CONVERT(VARCHAR(8),@Trandate,112)

    BETWEEN CONVERT(VARCHAR,YEAR(@Trandate)) + '0406'

    AND CONVERT(VARCHAR,YEAR(@Trandate)+1) + '0405'

    THEN CONVERT(DATETIME,CONVERT(VARCHAR,YEAR(@Trandate)) + '0406')

    WHEN CONVERT(VARCHAR(8),@Trandate,112)

    BETWEEN CONVERT(VARCHAR,YEAR(@Trandate)-1) +...

  • RE: Derived Column Syntax Help

    Something like this...

    Col1 : SUBSTRING(@[User::Test],1,FINDSTRING(@[User::Test],".",1) -1)

    Col2 : SUBSTRING(@[User::Test],FINDSTRING(@[User::Test],".",1) +1,LEN(@[User::Test]))

  • RE: group by column as sub header

    Hope this helps. You might want to refer this article

    ;WITH CTE AS

    (

    SELECT DISTINCT Header FROM Table_1

    )

    SELECT CONVERT(VARCHAR(MAX),Header + CHAR(10) +

    STUFF((

    SELECT CHAR(10) + Citation

    FROM Table_1

    WHERE Header = CTE.Header

    ORDER BY id

    FOR XML...

  • RE: processing xml

    Try this

    DECLARE @XML AS XML, @hDoc AS INT

    SET @XML =

    '<Root>

    <WPID>4</WPID>

    <WPName>??92</WPName>

    <Sum>0</Sum>

    <Result>03:30 , 18</Result>

    <Count>1</Count>

    </Root>'

    EXEC sp_xml_preparedocument @hDoc OUTPUT, @XML

    SELECT WPID, WPName, Sum, Result, Count

    FROM OPENXML(@hDoc, 'Root')

    WITH

    (

    WPID int 'WPID',

    WPName [varchar](100) 'WPName',

    Sum float 'Sum',

    Result...

  • RE: Using SSIS - Export multiple data sets to multiple tabs in single csv file

    A csv file cannot have multiple sheets - you can open a csv file in excel and add sheets to it but then you have to save as an excel...

  • RE: Package runs fine in BIDS but fails through agent

    Package variables are case-sensitive, can you check in the agent job while setting the values for the variables, the variable names are same as defined within the package.

  • RE: Compare XML in two tables

    CHECKSUM & BINARY_CHECKSUM cannot accept text, ntext, image, cursor, xml, and noncomparable common language runtime (CLR) user-defined types. Try converting the XML data-type to VARCHAR.

    With New_CodeXML as (

    Select

    binary_checksum(convert(varchar(max),new.PracticeOfficeXML)) as...

Viewing 15 posts - 31 through 45 (of 53 total)