sql-server-2005

Need To select Data From One Table After Minus With One Value

北慕城南 提交于 2019-12-13 19:22:54
问题 This question was migrated from Database Administrators Stack Exchange because it can be answered on Stack Overflow. Migrated 6 years ago . I have a table and a single value Table 1 SNo Amount 1 100 2 500 3 400 4 100 Value: 800 Now I want the result from the table is Minus the value and finally I would like to having rolling subtraction, that is subtract the Value 800 From Table 1's first Amount and then apply it to subsequent rows. Eg: for type-1 800 - 100 (Record1) = 700 700 - 500 (record2)

Displaying totals within a specified date range in Microsoft Access

跟風遠走 提交于 2019-12-13 18:17:49
问题 Although I have experience with SQL and generating HTML reports with PHP, I'm a relative beginner with Microsoft Access. I'm currently using Microsoft Access 2007 to connect to MSSQL Server 2005. I have a table of Reports that looks something like this: ReportID DateCreated Author ... I'd like to create a form that allows the user to specify a start date and an end date, which would then show the number of reports by each author within the specified date range. I've already done this in a

Time format hhmm to hh:mm sql server 2005

点点圈 提交于 2019-12-13 18:12:20
问题 I want to find the time difference so i am trying to use DATEDIFF option. But the problem is i am having the time values in hhmm format(eg: 1715). So it showing out of range error. so i want to convert it to hh:mm format. How to convert hhmm to hh:mm format? 回答1: Have you tried something like DECLARE @TimeVal VARCHAR(4) SELECT @TimeVal = '1715' select CONVERT(DATETIME,LEFT(@TimeVal,2) + ':' + RIGHT(@TimeVal,2),8) Output 1900-01-01 17:15:00.000 来源: https://stackoverflow.com/questions/4130485

How to copy a SQL Server 2005 database from local to the server

☆樱花仙子☆ 提交于 2019-12-13 17:52:25
问题 I want to export database from local computer to database server in SQL Server 2005. How can I restore database without having access to file system of database server 回答1: You can use SQL Server's built-in backup and restore functions. Make a backup of your local database, and write it on some network share (can be anywhere in the network, doesn't have to be on the database server): BACKUP DATABASE MyDatabase TO DISK = '\\Servername\Share\MyBackup.bak' Then, you can restore the database on

Local vs Global temp tables - When to use what?

末鹿安然 提交于 2019-12-13 17:27:21
问题 I have a report which on execution connects to the database with my_report_user username. There can be many end-users of the report. And in each execution a new connection to the database will be made with my_report_user (there is no connection pooling) I have a result set which I think can just be created once (may be on the first run of the report) and other report executions can just reuse that stuff. Basically each report execution should check whether this result set (stored as temp

How to make an SQL query to get some specific range of rows from a table

耗尽温柔 提交于 2019-12-13 17:03:13
问题 How to make an SQL query if there are 30 records in a table, and I want to pick rows from 12 to 20 where 12 and 20 are row numbers, not IDs? IDs Code 5 ABC 6 SDF 8 WSA 10 FSD 15 IOP . . . . 80 AWS 回答1: If you are using MS SQL Server then the row_number() function is available. Example: USE AdventureWorks2008R2; GO WITH OrderedOrders AS ( SELECT SalesOrderID, OrderDate, ROW_NUMBER() OVER (ORDER BY OrderDate) AS 'RowNumber' FROM Sales.SalesOrderHeader ) SELECT * FROM OrderedOrders WHERE

How do I find out what tables have data in a file in SQL Server?

馋奶兔 提交于 2019-12-13 16:37:51
问题 I want to drop a now supposedly redundant file in SQL Server (2005), but when I try to drop it I am told that the file is not empty. Does anyone know of a way to find out what data is still in this file so I can make whatever changes I need to allow me to drop it? 回答1: Assuming you're moved the table etc, you'll probably need to run: DBCC SHRINKFILE (MyLogicalFile, EMPTYFILE) --EMPTYFILE is the important bit!! See DBCC SHRINKFILE To check (this is a cut'n'paste of a usage script I use):

return only the last select results from stored procedure

耗尽温柔 提交于 2019-12-13 16:26:53
问题 The requirement says: stored procedure meant to search data, based on 5 identifiers. If there is an exact match return ONLY the exact match, if not but there is an exact match on the not null parameters return ONLY these results, otherwise return any match on any 4 not null parameters... and so on My (simplified) code looks like: create procedure xxxSearch @a nvarchar(80), @b nvarchar(80)... as begin select whatever from MyTable t where ((@a is null and t.a is null) or (@a = t.a)) and ((@b is

SQL Server 2005 Syntax Help - “Select Info based upon Max Value of Sub Query”

孤者浪人 提交于 2019-12-13 16:21:46
问题 The objective is below the list of tables. Tables: Table: Job JobID CustomerID Value Year Table: Customer CustomerID CustName Table: Invoice SaleAmount CustomerID The Objective Part 1: (easy) I need to select all invoice records and sort by Customer (To place nice w/ Crystal Reports) Select * from Invoice as A inner join Customer as B on A.CustomerID = B.CustomerID Part 2: (hard) Now, we need to add two fields: JobID associated with that customer's job that has the Maximum Value (from 2008)

convert int values to datetime in sql server

一个人想着一个人 提交于 2019-12-13 15:31:33
问题 I need to convert the int values of a year, month and day in a datetime using sql server. actually i' am using this DECLARE @MONTH INT DECLARE @YEAR INT DECLARE @DAY INT DECLARE @MAXDATE DATETIME DECLARE @MINDATE DATETIME SET @MONTH=12 SET @YEAR=2010 SET @DAY=1 SET @MINDATE=CONVERT(DATE,CAST (@YEAR AS VARCHAR)+ RIGHT ('0'+ CAST (@MONTH AS VARCHAR),2) + RIGHT ('0'+ CAST (@DAY AS VARCHAR),2)) SELECT @MINDATE and works ok, but i'm wondering if exist a better way to convert these values. 回答1: