sql-server-2005

Can I create a One-Time-Use Function in a Script or Stored Procedure?

徘徊边缘 提交于 2019-12-18 11:15:59
问题 In SQL Server 2005, is there a concept of a one-time-use, or local function declared inside of a SQL script or Stored Procedure? I'd like to abstract away some complexity in a script I'm writing, but it would require being able to declare a function. Just curious. 回答1: You can call CREATE Function near the beginning of your script and DROP Function near the end. 回答2: You can create temp stored procedures like: create procedure #mytemp as begin select getdate() into #mytemptable; end in an SQL

SQL Server find and replace in TEXT field

天大地大妈咪最大 提交于 2019-12-18 11:06:48
问题 I have a database in SQL Server 2005 that was brought up from SQL Server 2000 and is still using TEXT type fields instead of varchar(max). I need to find and replace a string of characters in the text field but all of the examples of how to do this that I have found don't seem like they would work for me. It seems the UPDATETEXT command requires that the two parameters "insert_offset" and "delete_length" be set explicitly but the string i am searching for could show up in the text at any

Windows Server 2008 as development machine - step by step

折月煮酒 提交于 2019-12-18 10:36:18
问题 I have found many tutorials about using Windows Server 2003 as a development machine, and very little information about Windows Server 2008 for the same purpose. For a nicer experience, I have followed the steps from Convert your Windows Server 2008 to a Workstation. I am searching for the requirements and installation order for IIS 7 with IIS 6 compatibility mode, .NET Framework 3.5 SP1 (does it require the installation of .NET Framework 3.0 feature, or can be installed directly), SQL Server

Most recent record in a left join

蓝咒 提交于 2019-12-18 10:14:54
问题 Imagine I have the following 3 tables in SqlServer: Customer (CustomerID, FirstName, LastName) Address (AddressID, CustomerID, Line1, City, State) Product (ProductID, CustomerID, Description) A customer can have multiple delivery addresses and mulitple products. What I would like to do is to list the number of customers for each State where the State is determined by the most recent Address record. Such as "How many customers last received a product in each State?". Therefore I'm not

protect stored procedure by deny view definition

删除回忆录丶 提交于 2019-12-18 09:42:03
问题 Is it enough for protecting stored procedure code if user has DENY VIEW ANY DATABASE DENY VIEW ANY DEFINITION ? User is granted execute sp only. Is it possible for him to trace or somehow see the code? I could not connect under that login with profiler but maybe some other ways available. 回答1: It's not clear what your goal is: are you trying to protect intellectual property; prevent users from seeing sensitive information in source code (e.g. passwords); prevent users from ALTERing the

Transposing Rows in to colums in SQL Server 2005

独自空忆成欢 提交于 2019-12-18 09:37:47
问题 I have an sql query "Select * from tablename" whose output is col1 col2 A 1 B 2 C 3 I want to modify the above output to below as following A B C 1 2 3 Please let me know how could I achieve this 回答1: You will need to perform a PIVOT. There are two ways to do this with PIVOT, either a Static Pivot where you code the columns to transform or a Dynamic Pivot which determines the columns at execution. Static Pivot: SELECT * FROM ( SELECT col1, col2 FROM yourTable ) x PIVOT ( min(col2) for col1 in

Comma-separated value insertion In SQL Server 2005

喜欢而已 提交于 2019-12-18 09:31:19
问题 How can I insert values from a comma-separated input parameter with a stored procedure? For example: exec StoredProcedure Name 17,'127,204,110,198',7,'162,170,163,170' you can see that I have two comma-separated value lists in the parameter list. Both will have the same number of values: if the first has 5 comma-separated values, then the second one also has 5 comma-separated values. 127 and 162 are related 204 and 170 are related ...and same for the others. How can I insert these two values?

to_date in SQL Server 2005

若如初见. 提交于 2019-12-18 09:29:26
问题 Does any one know how I would have to change the following to work with ms sql? WHERE registrationDate between to_date ('2003/01/01', 'yyyy/mm/dd') AND to_date ('2003/12/31', 'yyyy/mm/dd'); What I have read implies I would have to construct it using DATEPART() which could become very long winded. Especially when the goal would be to compare on dates which I receive in the following format "2003-12-30 10:07:42". It would be nice to pass them off to the database as is. Any pointers appreciated.

full-text search sql server 2005

雨燕双飞 提交于 2019-12-18 09:27:08
问题 I have got hold of a sql server 2008 developer edition and this is my data: if exists (select * from dbo.sysobjects where id = object_id(N'test') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table test create table test ( Id INT IDENTITY NOT NULL primary key, data NVARCHAR(255) not null ) insert into test (data) values ('Hello world'); insert into test (data) values ('Hello j-world'); I would like to find all rows which contain j-world whilst avoiding LIKE for efficiency reasons. If I try

Is NOLOCK the default for SELECT statements in SQL Server 2005?

。_饼干妹妹 提交于 2019-12-18 09:23:56
问题 I have only SQL Server 2008R2 installed though I need to communicate with customers having 2005. [1] tells: " NOLOCK This does not lock any object. This is the default for SELECT operations. It does not apply to INSERT, UPDATE, and DELETE statements" [2] doesn't seem to mention it, but my checking in SSMS/SS 2008R2 shows that nolock is not default hint for SELECT. Is WITH(NOLOCK) really default in SQL Server 2005 SELECT? Where is it written in BOL2005/2008? Update: Under "Where is it written"