sql-server-2000

Get the time of a datetime using T-SQL?

谁说胖子不能爱 提交于 2019-11-27 05:48:17
问题 How to get the time for a given datetime value? I have a datetime in database like this: 2010-09-06 17:07:28.170 and want only the time portion: 17:07:28.170 Is there a function for that or something? 回答1: Just to add that from SQL Server 2008, there is a TIME datatype so from then on you can do: SELECT CONVERT(TIME, GETDATE()) Might be useful for those that use SQL 2008+ and find this question. 回答2: In case of SQL Server, this should work SELECT CONVERT(VARCHAR(8),GETDATE(),108) AS

Grant execute permission for a user on all stored procedures in database?

走远了吗. 提交于 2019-11-27 05:09:25
问题 I generated script from old database, created a new database and imported all data from old database. So far so good, however, no user has execute rights for stored procedures. I know I can use GRANT EXECUTE ON [storedProcName] TO [userName] If it was just a few procedures, however, I have about 100 so what's the easiest way for me to grant execute access for a specific user to all of them? Thanks in advance. 回答1: Create a role add this role to users, and then you can grant execute to all the

Getting a query to index seek (rather than scan)

大兔子大兔子 提交于 2019-11-27 04:53:01
问题 Running the following query (SQL Server 2000) the execution plan shows that it used an index seek and Profiler shows it's doing 71 reads with a duration of 0. select top 1 id from table where name = '0010000546163' order by id desc Contrast that with the following with uses an index scan with 8500 reads and a duration of about a second. declare @p varchar(20) select @p = '0010000546163' select top 1 id from table where name = @p order by id desc Why is the execution plan different? Is there a

What Causes “Internal connection fatal errors”

痴心易碎 提交于 2019-11-27 04:30:26
问题 I've got a number of ASP.Net websites (.Net v3.5) running on a server with a SQL 2000 database backend. For several months, I've been receiving seemingly random InvalidOperationExceptions with the message "Internal connection fatal error". Sometimes there's a few days in between, while other times there are multiple errors per day. The exception is not limited to one site in particular, though they share business and data access assemblies. The error seems to always be thrown from SqlClient

How can I generate a temporary table filled with dates in SQL Server 2000?

回眸只為那壹抹淺笑 提交于 2019-11-27 04:26:29
I need to make a temporary table that holds of range of dates, as well as a couple of columns that hold placeholder values (0) for future use. The dates I need are the first day of each month between $startDate and $endDate where these variables can be several years apart. My original sql statement looked like this: select dbo.FirstOfMonth(InsertDate) as Month, 0 as Trials, 0 as Sales into #dates from customer group by dbo.FirstOfMonth(InsertDate) "FirstOfMonth" is a user-defined function I made that pretty much does what it says, returning the first day of the month for the provided date with

SQL Server: How to call a user-defined function (UDF) on linked server?

给你一囗甜甜゛ 提交于 2019-11-27 03:55:02
问题 i'm trying to call a User-Defined Function (UDF) on a linked server: CREATE FUNCTION [dbo].[UserGroupMembershipNames](@UserGUID uniqueidentifier) RETURNS VARCHAR(8000) AS BEGIN RETURN ASILIVE.ReportManager.dbo.UserGroupMembershipNames(@UserGUID) END This doesn't work, as documented in PRB: User-Defined Function Call in Four-Part Linked Server Query Fails with Error Message 170. They also give a workaround: For example, instead of the following query Select * from Linked_Server.northwind.dbo

How do I set the default database in Sql Server from code?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 03:54:13
问题 I can't seem to figure out how to set the default database in Sql Server from code. This can be either .Net code or T-Sql (T-Sql would be nice since it would be easy to use in any language). I searched Google and could only find how to do it in Sql Server Management Studio. 回答1: from: http://doc.ddart.net/mssql/sql70/sp_da-di_6.htm sp_defaultdb [@loginame =] 'login' , [@defdb =] 'database' 回答2: ALTER LOGIN should be used for SQL Server 2005 or later: http://technet.microsoft.com/en-us/library

SQL update query syntax with inner join

时光毁灭记忆、已成空白 提交于 2019-11-27 03:46:17
问题 Can anyone find my error in this query? I'm using SQL Server 2000 and I want to update all entries in the CostEntry table to the corresponding value in the ActiveCostDetails table. The where clause DOES work with a select statement. UPDATE CostEntry CE INNER JOIN ActiveCostDetails As AD ON CostEntry.lUniqueID = ActiveCostDetails.UniqueID SET CostEntry.sJobNumber = ActiveCostDetails.JobNumber WHERE CostEntry.SEmployeeCode = '002' AND SubString(CostCentre, 1, 1) = sDepartmentCode AND substring

SQL get the last date time record [duplicate]

限于喜欢 提交于 2019-11-27 02:30:22
问题 This question already has answers here : SQL Server: SELECT only the rows with MAX(DATE) (9 answers) Closed 2 years ago . I'm trying to get the last datetime record from a table that happens to store multiple status. My table looks like so: +---------+------------------------+-------+ |filename |Dates |Status | +---------+------------------------+-------+ |abc.txt |2012-02-14 12:04:45.397 |Open | |abc.txt |2012-02-14 12:14:20.997 |Closed | |abc.txt |2013-02-14 12:20:59.407 |Open | |dfg.txt

Remove trailing empty space in a field content

吃可爱长大的小学妹 提交于 2019-11-27 02:21:37
问题 I am using SQL server MSDE 2000. I have a field called notes of type nvarchar(65). The content is 'Something ' with an extra space after the content (quotes for clarity) in all the records. I used the following command. UPDATE TABLE1 SET notes = RTRIM(LTRIM(notes)) But it does not work. Is there any alternate way to do it? 回答1: Are you sure the query isn't working? Try: SELECT TOP 100 '~'+ t.notes +'~' FROM TABLE1 t TOP 100 will limit the results to the first 100 rows, enough to get an idea