sql-server-2005

PIVOT table for account data with columns for each month

。_饼干妹妹 提交于 2019-12-12 03:55:53
问题 The table I am looking in has the following columns: department_number, amount, date_created. I'm trying to create a table that shows the total amount for each department for each month in 2013, so it would look like this: Department_number, Jan Amount, Feb Amount, March Amt, etc.... Is this a case for pivot tables, or should I just run a different query for each month and join them? 回答1: Your case is certainly a candidate for using PIVOT table syntax. The below is a simple query which does

Find total time worked with multiple jobs / orders with overlap / overlapping times on each worker and job / order

删除回忆录丶 提交于 2019-12-12 03:43:47
问题 I searched night and day back when I was first starting out in the sql world for an answer to this question. Could not find anything similar to this for my needs so I decided to ask and answer my own question in case others need help like I did. Here is an example of the data I have. For simplicity, it is all from the Job table. Each JobID has it's own Start and End time that are basically random and can overlap, have gaps, start and end at the same time as other jobs etc. --Available-- JobID

There is insufficient system memory to run this query when creating temporary table

徘徊边缘 提交于 2019-12-12 03:09:57
问题 StringBuilder query = new StringBuilder(); query.Append("CREATE TABLE #Codes (Code nvarchar(100) collate database_default ) "); query.Append("Insert into #Codes (Code) "); int lengthOfCodesArray = targetCodes.Length; for (int index = 0; index < lengthOfCodesArray; index++) { string targetCode = targetCodes[index]; query.Append("Select N'" + targetCode + "' "); if (index != lengthOfCodesArray - 1) { query.Append("Union All "); } } query.Append("drop table #Codes "); on: cmd.ExecuteReader() I

Call to undefined function sqlsrv_connect()

左心房为你撑大大i 提交于 2019-12-12 03:09:30
问题 i wish to fire select query for login on user table . i am using php and ms msql server 2005 as backend my php code is correct but my database is on other p.c in network. i need to know is there any configuration setting needed to be done. i am using xampp V 1.8.3 including php 5.5.1 回答1: To install SQLSRV 3.0 to Apache (I assume) in Windows platform, here are the steps: Put the driver file in your PHP extension directory. Modify the php.ini file to include the driver. For example: extension

Datediff GETDATE Add

拈花ヽ惹草 提交于 2019-12-12 03:09:18
问题 In this type of code, AND Orders.ShipDate >= DATEADD(Day, Datediff(Day,0, GetDate() -6), 0) It supposed to pull records with the date 6 days ago, until today. How can I make it pull records from 7 days ago until yesterday? I know changing -6 to -7 will pull records from 7 days ago, but which variable is the end of the date span so I can change it to -1 ? 回答1: It's not a date span. The condition you have there is really only one condition: greater than. The right side of the greater than is 6

How do I remove duplicates in paging

女生的网名这么多〃 提交于 2019-12-12 03:04:36
问题 table1 & table2: table1 & table2 http://aftabfarda.parsfile.com/1.png SELECT * FROM (SELECT DISTINCT dbo.tb1.ID, dbo.tb1.name, ROW_NUMBER() OVER (ORDER BY tb1.id DESC) AS row FROM dbo.tb1 INNER JOIN dbo.tb2 ON dbo.tb1.ID = dbo.tb2.id_tb1) AS a WHERE row BETWEEN 1 AND 7 ORDER BY id DESC Result: Result... http://aftabfarda.parsfile.com/3.png (id 11 Repeated 3 times) How can I have this output: ID name row -- ------ --- 11 user11 1 10 user10 2 9 user9 3 8 user8 4 7 user7 5 6 user6 6 5 user5 7

Find the next occurance of a day of the week in SQL

六眼飞鱼酱① 提交于 2019-12-12 02:56:56
问题 I'm trying to update a SQL report sproc's WHERE clause to check whether a given date falls on or before the next occurrence of a class. Classes have a StartDate and occur once per week on the same day each week. Given the StartDate, how can I find the next occurrence of that day of the week? E.G. If the StartDate is 1/18/2012, a Wednesday, and I run the report as of today, 1/26/2012, I need to find 2/1/2012 which is the next Wednesday after 1/26. If the StartDate is 1/19, a Thurs, and I run

update oldID field based on fields in the same table

拟墨画扇 提交于 2019-12-12 02:48:45
问题 I need help with the following query. create table #table1 (id int not null primary key identity, customer_name varchar(25), usage float, oldID int null ) insert into #table1 values('ABC',46.5,null) insert into #table1 values('ABC',46.5,null) insert into #table1 values('DEF',36.8,null) insert into #table1 values('XYZ',50.1,null) insert into #table1 values('DEF',36.8,null) insert into #table1 values('XYZ',50.1,null) select * from #table1 I want my table to be updated like this id customer_name

C# import excel filesheet to sql database error

北城以北 提交于 2019-12-12 02:45:15
问题 I have met the error: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. I'm using SQL Server 2005 and Visual Studio 2005. I met this error during the import of an excel filesheet to a table in my sql table. Below is my code: #region Using directives using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.OleDb; using System.Data

Iterating Through Table in High-Performance Code

↘锁芯ラ 提交于 2019-12-12 02:38:26
问题 Supposing I have two temporary tables CREATE TABLE TableA ( SomeValue NVARCHAR(64) ) CREATE TABLE TableB ( SomeValue NVARHCAR(64) ) and a final table CREATE TABLE TableC ( SomeValue1 NVARCHAR(64), SomeValue2 NVARHCAR(64) ), what is the best way to insert into TableC every possible combination of values from TableA and TableB in a high-perfomance fashion? I know cursors must be the least thing to think about, but will two WHILE loops do it fast enough? 回答1: A simple Cartesian product which is