sql-server-2005

After 13th row Dynamic and in 12th row static values with a formula

泪湿孤枕 提交于 2020-01-25 23:47:12
问题 Below is the SQL Query I used to create as view CREATE VIEW [v_AMP_C] AS SELECT dbo.IC_Raw_In.I_Date, dbo.IC_Raw_In.I_O_P, dbo.IC_Raw_In.I_O_H, dbo.IC_Raw_In.I_O_L, dbo.IC_Raw_In.I_C_O, dbo.AMPS12_C.AMPS12_C FROM dbo.IC_Raw_In INNER JOIN dbo.AMPS12_C ON dbo.IC_Raw_In.I_Serial = dbo.AMPS12_C.i_serial and the data is imported to this table by useing a bulk insert dbo.IC_Raw_In and data type are Money except I_Date. Then when i ran the query i.e,. select * from v_AMP_C i got the below as output

The correct syntax for a T-SQL subquery and a possible join

北城以北 提交于 2020-01-25 11:38:09
问题 What would be the correct syntax and join (if any) of a subquery that would return all of the employees first and last name from the employee’s table, and return their department name from the department table, but only those employees who more than the average salary for their department? Thanks for your answers 回答1: This query should give you what you are looking for. select firstName, lastName, departmentName from Employees e join (select departmentID, departmentName, AVG(salary) AS

Get top 1 row of each group

可紊 提交于 2020-01-25 09:26:28
问题 I have a table which I want to get the latest entry for each group. Here's the table: DocumentStatusLogs Table |ID| DocumentID | Status | DateCreated | | 2| 1 | S1 | 7/29/2011 | | 3| 1 | S2 | 7/30/2011 | | 6| 1 | S1 | 8/02/2011 | | 1| 2 | S1 | 7/28/2011 | | 4| 2 | S2 | 7/30/2011 | | 5| 2 | S3 | 8/01/2011 | | 6| 3 | S1 | 8/02/2011 | The table will be grouped by DocumentID and sorted by DateCreated in descending order. For each DocumentID , I want to get the latest status. My preferred output:

Deadlock when querying INFORMATION_SCHEMA

為{幸葍}努か 提交于 2020-01-25 08:26:28
问题 I have a process which dynamically alters my SQL2K5 table structure according to changes in a published meta-data layer. For example, if a new column needs to be added and the table has NO dependancies - the steps would be: 1. Create scripts using T-SQL for any indexes & primary keys that already exist on the table [these scripts are included below] 2. Drop the table 3. Re-create the table from the meta-layer that has the new column 4. Execute the scripts created in step#1 5. Populate the

Select non duplicate values from rows that are less than a specified number of minutes apart

感情迁移 提交于 2020-01-25 06:25:29
问题 I have a huge table with the following format: DATETIME NUMBER -------------------------------------- 2009-03-31 16:05:52.000 2453651622 2009-03-31 16:16:12.000 30206080 2009-03-31 16:16:16.000 16890039 2009-03-31 16:16:28.000 2452039696 2009-03-31 16:16:33.000 140851934 2009-03-31 16:16:51.000 2453120306 2009-03-31 16:16:57.000 2453120306 ... 2009-04-01 21:15:24.000 2453651622 How can I select the rows that don't have duplicate numbers in the second column if they occur less than 15 minutes

MVC3 - Authenticate with SQL Server Accounts

▼魔方 西西 提交于 2020-01-25 04:22:05
问题 I couldn't find anything useful to this problem and I never used authentication in a web application before. So anything with / without cookies is new for me. We've got an existing (non-web-)program using SQL Server accounts for authentication. Now, I want to do the same with my MVC3 project. Every user has the same rights inside the database. The (non-web-)program handles the rights itself. After logging in successful (with an SQL account), the login name is mapped to an entity in the

Printing the current value and previous value between the date range

冷暖自知 提交于 2020-01-25 03:43:24
问题 I have a sample data like this ID DATE TIME STATUS --------------------------------------------- A 01-01-2000 0900 ACTIVE A 05-02-2000 1000 INACTIVE A 01-07-2000 1300 ACTIVE B 01-05-2005 1000 ACTIVE B 01-08-2007 1050 ACTIVE C 01-01-2010 0900 ACTIVE C 01-07-2010 1900 INACTIVE From the above data set, if we only focus on ID='A' we note that A was initally active, then became inactive on 05-02-2000 and then it was inactive until 01-07-2000 . Which means that A was inactive from 05-Feb-2000 to 01

The permissions granted to user 'servername/iusr-username' are insufficient for performing this operation. (rsAccessDenied)

依然范特西╮ 提交于 2020-01-24 22:47:08
问题 I have tried everything that most forums have said and still cannot get other people in the network to see this report. Here's the things I have tried: in servername/reports under properties tab i have added my user domain/username and given him all 5 roles ( Browser , Content Manager , My Reports , Publisher , Report Builder ) in the site settings --> Configure Site wide security --> domain / username , i have given System Administrator role. In IIS , I have given both the reports and

Problem with update sql with excel

…衆ロ難τιáo~ 提交于 2020-01-24 21:31:26
问题 I have a problem with this query: UPDATE Provinces SET Provinces.DefaultName=T2.Defaultname FROM Provinces INNER JOIN OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\provinces.xlsx;HDR=YES', 'SELECT Code, Defaultname FROM [Arkusz1$]') T2 On Provinces.Code = t2.Code WHERE Provinces.Code = T2.Code I get error: Msg 7399, Level 16, State 1, Line 1 The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" reported an error. The provider did not give any information

SQL Pivot using an XML column

我的梦境 提交于 2020-01-24 21:18:05
问题 Does anyone have an example of a pivot using a table with an XML column in it - specifically turning some of the elements in the xml column into a column in the pivot table? I'm trying to build one, but the syntax is killing me; xml in sql is damn hard to work with, compared to xml in C#. I suspect this is impossible, but it wouldn't hurt to check :) 回答1: Here is a simple example that has Stores with Product details stored in xml. The pivot is at the bottom which shows the stores and a sum of