sql-server-2000

SQL Server 2000: how do I return only the number from a phone number column

∥☆過路亽.° 提交于 2019-12-01 20:24:46
问题 I'm trying to strip out the "(", ")", "-", "x" or "X" "ext" and spaces from each phone number so I am left with only the first 10 digits or 1st 10 numbers of a phone number. Is there a simple way to allow only the first 10 digits to pass through in sql 2000. I was thinking about using replace but it requires a replace for each character or group of characters and is not very neat. Is there a way with a standard install of sql2000 to return only the first 10 numbers. Examples before and after

SQL joining multiple tables

柔情痞子 提交于 2019-12-01 19:15:40
Using Microsoft SQL 2000, I will like to join multiples tables (A, B, C, and D) together. I know table A always exists. However, I only know at least one of the table form (B, C, D) exists. Is there any way I could do something like this to accomplish what I am trying to do? Select * form table a If table b exists left Join table b on a.id = b.id If table c exists left Join table c on a.id = c.id If table d exists left Join table d on a.id = d.id You'll have to check the data dictionary views for that and use dynamic SQL declare @myquery varchar(1000) set @myquery = 'Select * from a ' if

SQL - Ugly combination of GROUP BY and COALESCE

大兔子大兔子 提交于 2019-12-01 18:10:24
问题 I have a table with data similar to the following: [ID], [State], [foo], [DateCreated], [DateUpdated] The longer I work on this, the uglier my SQL is getting, which tells me I'm probably doing something wrong. What I want is a unique list of each State so long as foo is always the same for that State (if foo is not the same for all records in that State, I don't want that State at all) . Also, I want to COALESCE DateCreated and DateUpdated and want the maximum value for that State. So given

What causes SQL Server to return the message 'The statement has been terminated'?

一曲冷凌霜 提交于 2019-12-01 17:38:56
I have a very simple INSERT statement being executed from a PHP script running on a Linux Apache web server. I can run the query fine from within SQL Management Studio and it normally runs fine from PHP as well. However, every once in awhile I get an error message from my PHP script that the query failed and the mssql_get_last_message() function returns 'The statement has been terminated'. What sources can cause this message to be returned from SQL Server? You have found one of the most annoying parts of SQL Server. There are situations where an error can be raised, and SQL will generated two

Get last inserted UNIQUEIDENTIFIER in SQL Server 2000

白昼怎懂夜的黑 提交于 2019-12-01 17:02:47
The OUTPUT clause is compatible with SQL Server 2005 but not SQL Server 2000. How do I convert this command to work in SQL Server 2000? CREATE TABLE sample ( ID uniqueidentifier NOT NULL DEFAULT newid(), Title varchar(30) NOT NULL ) INSERT INTO sample (Title) OUTPUT INSERTED.ID VALUES ('Test1') I need the command to retrieve the ID since the INSERT command needs to be called from a stored procedure. Thanks for any help! DECLARE @uid uniqueidentifier SET @uid = newid() INSERT INTO sample (ID, Title) VALUES (@uid,'Test1') SELECT @uid AS ID 来源: https://stackoverflow.com/questions/5863168/get-last

What causes SQL Server to return the message 'The statement has been terminated'?

て烟熏妆下的殇ゞ 提交于 2019-12-01 16:38:29
问题 I have a very simple INSERT statement being executed from a PHP script running on a Linux Apache web server. I can run the query fine from within SQL Management Studio and it normally runs fine from PHP as well. However, every once in awhile I get an error message from my PHP script that the query failed and the mssql_get_last_message() function returns 'The statement has been terminated'. What sources can cause this message to be returned from SQL Server? 回答1: You have found one of the most

Linked Server Performance and options

ぐ巨炮叔叔 提交于 2019-12-01 15:52:12
At work we have two servers, one is running an application a lot of people use which has an SQL Server 2000 back end. I have been free to query this for a long time but can't add anything to it such as stored procedures or extra tables. This has lead to us having a second SQL Server linked to the first one and me building up a library of stored procedures that query data from both sides using linked server. Some of these queries are taking longer than what I would like. Can someone point me to some good articles about using linked servers? I am particularly interested in finding out what data

Getting bcp.exe to escape terminators

大兔子大兔子 提交于 2019-12-01 15:43:50
I need to export some data using SQL Server 2000's BCP utility. Sometimes my data contains characters, such as \t and \n, that I need to use as column and row terminators. How do I get BCP to escape characters it's using as terminators as it outputs the data, so that I can actually import the data in another program? For example, one of my columns is text data, and includes tabs and newlines. BCP just exports them as-is, and the program I'm trying to import them with gets confused because the data ends in the middle of a line and/or a line contains extra columns for no apparent reason. This

Linked Server Performance and options

◇◆丶佛笑我妖孽 提交于 2019-12-01 15:34:40
问题 At work we have two servers, one is running an application a lot of people use which has an SQL Server 2000 back end. I have been free to query this for a long time but can't add anything to it such as stored procedures or extra tables. This has lead to us having a second SQL Server linked to the first one and me building up a library of stored procedures that query data from both sides using linked server. Some of these queries are taking longer than what I would like. Can someone point me

Is it possible to calculate MD5 hash directly in T-SQL language?

前提是你 提交于 2019-12-01 15:25:10
问题 I need to hash (MD5) all the password in our Sql Server 2000 database. I can easily generate a C#/VB.NET program to convert (hash) all the passwords, but I was wondering (more for my education than for a real compelling need) if it was possible to calculate MD5 hash directly in T-SQL. Thanks to anyone who will answer. 回答1: It is using this code, but it is not native to the language. http://www.codeproject.com/KB/database/xp_md5.aspx 回答2: In 2005 and later, you can call the HashBytes()