Skip to content
Advertisement

Tag: tsql

How to calculate running total (month to date) in SQL Server 2008

I’m trying to calculate a month-to-date total using SQL Server 2008. I’m trying to generate a month-to-date count at the level of activities and representatives. Here are the results I want to generate: From the following tables: ACTIVITIES_FACT table LU_TIME table I’m not sure how to do this: I keep running into problems with multiple-counting or aggregations not being allowed

Transform and group row data into columns

I’m looking for a way to combine different rows into a single row with columns. Let’s take this example table: Desired output: Please note that Data centers are not necessarily these three, they can be N different data centers that I will not know in advance. Answer With a known set of sourceDataCenter values, you can just use a simple

Get number of employees who worked in more than one department with SQL query

I’m trying to figure out a query which show the number (amount) of employees who worked in more than 1 departments. Here the table name and fields: Employee(id_employee, employee_name, salary) Department(id_dept, dept_name, budget) Department_Employee(id_employee, id_dept, workhours_percentage) Suppose the content of Department_Employee table is With a right query, the result should be 2 (employees), because there are 2 employees who work

Unpivot with column name

I have a table StudentMarks with columns Name, Maths, Science, English. Data is like I want to get it arranged like the following: With unpivot I am able to get Name, Marks properly, but not able to get the column name in the source table to the Subject column in the desired result set. How can I achieve this? I

how to convert date to a format `mm/dd/yyyy`

I’m having a sql table with date column named CREATED_TS which holds the dates in different format eg. as shown below Now I want to convert these to format mmddyyyy before as i am comparing the dates in WHERE clause of my SELECT query. I tried using but got the result as, I need the result as eg. 02/20/2012 in

Advertisement