Forum Replies Created

Viewing 15 posts - 166 through 180 (of 898 total)

  • RE: Separate one column in many columns

    Change the final SELECT statement to something like this

    SELECT*, CAST( ( game1 + game2 + game3 + game4 + game5 ) / 5.0 AS NUMERIC(10,1) ) AS [percent]

    FROMcte_Students

  • RE: Get 2 column result from 1 field

    Can you post the query you are using. That might give us some idea.

  • RE: Indexing

    Excellent question. Keep it up.

  • RE: How To Get a row(date) for each month

    Teee (6/13/2013)


    @kingston Dhasian, Thank you so much for the script that's returning the dates it works perfectly.

    I am glad it worked for you and I hope you understand what...

  • RE: Three months before current month

    One way to achieve the results..

    DECLARE @datefrom DATETIME

    DECLARE @dateto DATETIME

    SET@datefrom = '01/01/2013'

    SET@dateto = DATEADD(DAY,-1,DATEADD(MONTH,DATEDIFF(MONTH,0,CURRENT_TIMESTAMP)-2,0))

    SELECT @datefrom,@dateto

  • RE: How To Get a row(date) for each month

    Something like this?

    DECLARE@min-2 DATETIME

    DECLARE@max-2 DATETIME

    SELECT@min-2 = MIN(dtePostedToWebsiteDate)

    FROMdtlVacancyPostAudit

    WHEREbitPostToWebSite = 1

    SET@max-2 = DATEADD(MONTH,DATEDIFF(MONTH,0,CURRENT_TIMESTAMP)+1,0)

    SELECTDATENAME(MONTH,@min) AS MinMonth,

    YEAR(@min) AS MinYear,

    DATEADD(MONTH,sv.number,@min)

    FROMmaster.dbo.spt_values AS sv -- You can use a Tally table instead as well

    WHEREsv.type = 'P'

    ANDDATEADD(MONTH,sv.number,@min) <...

  • RE: How to format the data in column in sql server

    One way to achieve the results

    DECLARE @YourTableName TABLE

    (

    ColumnName VARCHAR(20)

    )

    INSERT@YourTableName

    SELECT'10.12.2012' UNION ALL

    SELECT'12-10-2012' UNION ALL

    SELECT'2012/10/12'

    SELECTCASE

    WHEN ColumnName LIKE '%.%' THEN CONVERT(DATETIME,ColumnName,104)

    WHEN ColumnName LIKE '%-%' THEN CONVERT(DATETIME,ColumnName,110)

    WHEN ColumnName LIKE '%/%' THEN CONVERT(DATETIME,LEFT(ColumnName,5)+RIGHT(ColumnName,2)+SUBSTRING(ColumnName,5,3),111)

    END AS NewColumn,...

  • RE: ORDER BY the total of a GROUP BY

    One small observation..

    Its not a good idea to use a function in your WHERE clause if you can avoid it as it makes the query non-SARGable

    You can modify Mark's code...

  • RE: Using between in where clause from subquery

    tshad (6/12/2013)


    But I need to do this in a where clause, possible using a subquery but how do I use the "BETWEEN" there?

    Why? Any particular reason?

    SELECT *

    FROM @Client cl

    JOIN...

  • RE: Separate one column in many columns

    It happened because the data types for columns game1, game2,...game5 were taken as VARCHAR

    The below code will avoid the issue

    ; WITH cte_Students AS

    (

    SELECT*,

    CASE WHEN SUBSTRING(rate, 1, 1) = '*' THEN...

  • RE: Hierarchy of managers for specific employee

    It would be really helpful if you provide the DDL of the tables Employee and Supervisor

    Some sample data and the expected results based on the sample data would help us...

  • RE: Calculate Previous Business Day Exclude Saturday, Sunday and Holiday

    What input will you be passing to the UDF?

    It would be helpful if you can us the DDL of the table "tblHoliday" as well.

  • RE: Separate one column in many columns

    You can use a CTE or a Derived table like this

    ; WITH cte_Students AS

    (

    SELECT*,

    CASE WHEN SUBSTRING(rate, 1, 1) = '*' THEN '10' ELSE SUBSTRING(rate, 1, 1) END AS game1,

    CASE WHEN...

  • RE: Update Performance

    Do you really want to update all the 63 million rows?

    Check if you can put some filter to reduce the number of rows that will be affected.

  • RE: Division problem in SQL

    The link below has the answer to your question

    http://msdn.microsoft.com/en-us/library/ms175009.aspx

    If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the...

Viewing 15 posts - 166 through 180 (of 898 total)