sql-server-2014

How to find gaps in a sequence of numbers in SQL Server

丶灬走出姿态 提交于 2021-02-07 10:38:19
问题 I am trying to find the smallest missing number in this table. +------+--------+ | id | number | +------+--------+ | 902 | 1 | | 908 | 2 | | 1007 | 7 | | 1189 | 8 | | 1233 | 12 | | 1757 | 15 | +------+--------+ In the number column, you can see there are several gaps between the numbers. I need to get the number after the smallest gap. So in the case above I need the number 3. Because 2 is the smallest number after a gap. 回答1: I would use lead() : select min(id) + 1 from (select t.*, lead(id)

SSRS 2014 URL access always generates XLS instead of XLSX when format is EXCEL

别等时光非礼了梦想. 提交于 2021-01-28 04:16:36
问题 I have SQL Server 2014 and I'm trying to access my reports via the URL access. As I understand, the Excel format should be giving me an XLSX file which supports an unlimited number of rows. However, after looking at my log files I noticed that I was getting maximum row errors for any reports with more then 65536 rows. After looking into this I discovered that any time I request the reports via URL with format as EXCEL, they generate a XLS file instead of XLSX. If I run the reports out of

DECRYPTBYPASSPHRASE is not working after creating them with EncryptByPassPhrase

℡╲_俬逩灬. 提交于 2021-01-27 13:32:47
问题 I have a table: CREATE TABLE TempHashedValues( HashedValues varbinary(200) ) Now, I am inserting encrypted values to it using, so that could be used later: Insert into TempHashedValues values ( EncryptByPassPhrase('key', 'SecretEncoded' )) Now when I am trying to decrypt them using same key: Select TOP 1 DECRYPTBYPASSPHRASE('key',HashedValues) from TempHashedValues I am just getting the binary value back , not the value I encrypted !! What am I missing? 回答1: As stated here http://sqlity.net

Does a SELECT COUNT(*) query have to do a full table scan?

谁都会走 提交于 2021-01-05 06:31:03
问题 Does a query that gets the count of all rows in a table have to do a full table scan or does SQL Server maintain a count of rows somewhere? SELECT COUNT(*) FROM TABLE_NAME; The table TABLE_NAME has a primary key, and therefore a clustered index, and looks like so: CREATE TABLE TABLE_NAME ( Id int PRIMARY KEY IDENTITY(1, 1), Name nvarchar(50) NOT NULL ); I am using Microsoft SQL Server 2014. 回答1: The server will always read all records (if there's an index then it will scan the entire index)

Does a SELECT COUNT(*) query have to do a full table scan?

谁都会走 提交于 2021-01-05 06:30:59
问题 Does a query that gets the count of all rows in a table have to do a full table scan or does SQL Server maintain a count of rows somewhere? SELECT COUNT(*) FROM TABLE_NAME; The table TABLE_NAME has a primary key, and therefore a clustered index, and looks like so: CREATE TABLE TABLE_NAME ( Id int PRIMARY KEY IDENTITY(1, 1), Name nvarchar(50) NOT NULL ); I am using Microsoft SQL Server 2014. 回答1: The server will always read all records (if there's an index then it will scan the entire index)

Does a SELECT COUNT(*) query have to do a full table scan?

我的梦境 提交于 2021-01-05 06:27:04
问题 Does a query that gets the count of all rows in a table have to do a full table scan or does SQL Server maintain a count of rows somewhere? SELECT COUNT(*) FROM TABLE_NAME; The table TABLE_NAME has a primary key, and therefore a clustered index, and looks like so: CREATE TABLE TABLE_NAME ( Id int PRIMARY KEY IDENTITY(1, 1), Name nvarchar(50) NOT NULL ); I am using Microsoft SQL Server 2014. 回答1: The server will always read all records (if there's an index then it will scan the entire index)

Using OFFSET-FETCH, how to default number of rows to “all rows”?

一个人想着一个人 提交于 2021-01-02 08:16:33
问题 Envision a stored procedure which takes @skip (offset) and @take (maximum number of rows to return. If @take is null , then I want to return "all rows after applying the offset". I can accomplish this by counting the number of rows in the table/view if @take is null , but then I have to perform two queries which is, of course, not optimal. I was hoping there was an option similar to FETCH [NEXT] ALL ROWS . DECLARE @skip BIGINT = 0; DECLARE @take BIGINT = NULL; IF (@take IS NULL) SET @take =

SQL Server Change Data Capture - Capture user who made the change

六月ゝ 毕业季﹏ 提交于 2020-07-21 04:15:09
问题 Concerning SQL Server Change Data Capture , can you track the User who has made the change to the row/column data or is there anyway to extend CDC to allow this? I couldn't see anything in the documentation. 回答1: You can't capture username with CDC.. You have to use Auditing to do so or if this is a one time request,you can query TLOG.. Below is the connect item requesting the same.. CDC : options to capture more data (username, date/time, etc) You also can use triggers as per this article

Issue in saving current date with UTC time in sql server

妖精的绣舞 提交于 2020-07-10 08:24:21
问题 I want save date with UTC time zone in sql server 2014. I have used ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of("UTC")) to get the current date time and persisting this to db using Hibernate session object. While debugging I can see that in Java program date is fine like this 2019-09-25T13:22:29.573Z[UTC] , but after saving in database column it is something like this 2019-09-25 18:53:23.3630000 . It's automatically converting the time part according to system time. Can anyone

Why isn't my single-character full text search working?

家住魔仙堡 提交于 2020-06-12 15:19:52
问题 Given this code, I'm getting back no results: SELECT TOP 10 * FROM MyTable WHERE CONTAINS(TextColumn, '"W"') Things I've checked: Longer words return a result There are no stop LIST associated with this index There is definitely text such as "James W Brown" in the column The full text index is up to date. EDIT: I was looking for a stop lists, not a stop word, associated with the index. 回答1: The answer is to make sure you have an empty stop list associated with the index. It isn't enough to