Forum Replies Created

Viewing 15 posts - 196 through 210 (of 761 total)

  • RE: Substrating the columns from two queries

    dwain.c (8/24/2012)


    Since row ordering is not guaranteed by SQL, how do you know you're subtracting the right numbers at each row?

    Yes it should be ordered according to the OP's requirement....

  • RE: Substrating the columns from two queries

    You can do it as follows:

    --Creating Tables

    Create table Ex

    (Value int )

    Create Table Ex1

    (Value int )

    --Inserting Sample Data

    Insert Into Ex

    Select 1

    Union ALL

    Select 2

    Union ALL

    Select 3

    Union ALL

    Select 4

    Union ALL

    Select 5

    Insert Into Ex1

    Select...

  • RE: Please give query for below output

    You can do it as follows:

    --Creating Tables

    Create Table Ex

    (TargetId int )

    Create Table Ex1

    (QID int )

    Create Table Ex2

    (KitId int,

    Targetid int,

    QId int )

    --Inserting Sample Data

    Insert into Ex

    Select 100

    Union...

  • RE: Extract string between delimiters

    This would work in all cases I suppose:

    Declare @string Varchar(max) = 'ertgfh_fert_dfgt_ghty'

    Select SubString(@string, (CHARINDEX('_', @string, 0) + 1),

    (CharIndex('_', RIGHT(@string, (LEN(@string) - (CharIndex('_', @string, 0)))), 0) - 1)) As NewString

  • RE: Extract string between delimiters

    Try this:

    Select SubString('abc_def_cet_qwe', (CHARINDEX('_', 'abc_def_cet_qwe', 0) + 1), 3) As NewString

    If the length is not fixed then you can use this approach:

    Select SubString('abc_def_cet_qwe', (CHARINDEX('_', 'abc_def_cet_qwe', 0) + 1),

    (CharIndex('_', RIGHT('abc_def_cet_qwe',...

  • RE: find max

    raghuldrag (8/17/2012)


    ya its workin..... suppose i need the particular top 3rd postion of max salary means how to modify

    Declare @position Varchar(30)

    Set @position = 'sales'

    Select Top 1 * From

    ...

  • RE: find max

    SomewhereSomehow (8/17/2012)


    vinu512 (8/17/2012)


    From what I understand, this should do it:

    Declare @position Char(33)

    Set @position = 'sales'

    Select ename, job From

    (

    Select *, ROW_NUMBER() Over (Partition By job Order By Sal) As rn From...

  • RE: Converting Dynamic Pivot to Parameterized Query

    dwain.c (8/17/2012)


    Look at BOL: http://msdn.microsoft.com/en-us/library/ms188001(v=sql.105).aspx

    Does the first example on that page do what you want?

    If not, perhaps I'm misunderstanding.

    Yes, that's the article I read to start with this. I was...

  • RE: find max

    From what I understand, this should do it:

    Declare @position Char(33)

    Set @position = 'sales'

    Select ename, job From

    (

    Select *, ROW_NUMBER() Over (Partition By job Order By Sal) As rn From Ex

    )...

  • RE: How to grab characters before and after a string

    This is on the same lines but a little different in logic:

    Select LEFT([Flammables/solvents], (CHARINDEX('/', [Flammables/solvents]) - 1) ) As Flammables,

    RIGHT([Flammables/solvents], (CHARINDEX('/', Reverse([Flammables/solvents])) - 1) ) As...

  • RE: Filer on Period for Active Versions only.

    The solution is fine...but with so many Cast and Parsename function calls, I think that if you are working on a big table with lots of data then the performance...

  • RE: Date Format Problem

    Thanks for all the help guys. I think I should rather handle the formatting at the Application Level. 🙂

  • RE: Pivot And Unpivot Table

    Jeff Moden (8/6/2012)


    vinu512 (8/4/2012)


    Using Pivot/unpivot could be more than just a matter of choice. You can definitely avoid the Pivot with Case+Group but then you come across situations where you...

  • RE: Pivot And Unpivot Table

    dwain.c (8/6/2012)


    vinu512 (8/6/2012)


    dwain.c (8/6/2012)


    SomewhereSomehow (8/3/2012)


    When you asking about alternate solution you, do mean funtctional equivalent? you may use case+group by instead of pivot, and cross apply instead of unpivot. You...

  • RE: Date Format Problem

    calvo (8/6/2012)


    what is the collation and data type of the field storing the current date?

    Collation: SQL_Latin1_General_CP1_CI_AS

    DataType: DateTime

    GSquared (8/6/2012)


    Dates in SQL Server aren't stored in any of those formats. They're...

Viewing 15 posts - 196 through 210 (of 761 total)