sql-server-2000

Most efficient method to detect column change in MS SQL Server

纵饮孤独 提交于 2019-11-27 19:05:42
Our system runs on SQL Server 2000, and we are in the process of preparing for an upgrade to SQL Server 2008. We have a lot of trigger code where we need to detect a change in a given column and then operate on that column if it has changed. Obviously SQL Server provides the UPDATE() and COLUMNS_UPDATED() functions, but these functions only tell you which columns have been implicated in the SQL statement, not which columns have actually changed. To determine which columns have changed, you need code similar to the following (for a column that supports NULLs): IF UPDATE(Col1) SELECT @col1

SQL Server: How to make server check all its check constraints?

你离开我真会死。 提交于 2019-11-27 18:47:50
It seems that some scripts generated by Enterprise Manager* (or not, it doesn't matter) created check constraints WITH NOCHECK . Now when anyone modifies the table, SQL Server is stumbling across failed check constraints , and throwing errors. Can i make SQL go through all its check constraints, and check them? Running: sp_msforeachtable 'ALTER TABLE ? CHECK CONSTRAINT all' only enables previously disabled check constraints, it doesn't actually check them. Footnotes * SQL Server 2000 Nathan DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS won't actually make your constraints trusted. It will report

TSQL - Is it possible to define the sort order?

*爱你&永不变心* 提交于 2019-11-27 18:47:14
Is it possible to define a sort order for the returned results? I would like the sort order to be 'orange' 'apple' 'strawberry' not ascending or descending. I know ORDER BY can do ASC or DESC but is there a DEFINED('orange', 'apple', 'strawberry') type thing? This will be running on SQL Server 2000. It's incredibly clunky, but you can use a CASE statement for ordering: SELECT * FROM Blah ORDER BY CASE MyColumn WHEN 'orange' THEN 1 WHEN 'apple' THEN 2 WHEN 'strawberry' THEN 3 END Alternately, you can create a secondary table which contains the sort field and a sort order. TargetValue SortOrder

How can I insert binary file data into a binary SQL field using a simple insert statement?

怎甘沉沦 提交于 2019-11-27 18:05:36
I have a SQL Server 2000 with a table containing an image column. How do I insert the binary data of a file into that column by specifying the path of the file? CREATE TABLE Files ( FileId int, FileData image ) casperOne If you mean using a literal, you simply have to create a binary string: insert into Files (FileId, FileData) values (1, 0x010203040506) And you will have a record with a six byte value for the FileData field. You indicate in the comments that you want to just specify the file name, which you can't do with SQL Server 2000 (or any other version that I am aware of). You would

MSSQL Select statement with incremental integer column… not from a table

不羁的心 提交于 2019-11-27 15:45:53
问题 I need, if possible, a t-sql query that, returning the values from an arbitrary table, also returns a incremental integer column with value = 1 for the first row, 2 for the second, and so on. This column does not actually resides in any table, and must be strictly incremental, because the ORDER BY clause could sort the rows of the table and I want the incremental row in perfect shape always... Thanks in advance. --EDIT Sorry, forgot to mention, must run on SQL Server 2000 回答1: For SQL 2005

T-SQL Between Dates Confusion

青春壹個敷衍的年華 提交于 2019-11-27 15:12:07
I am working with T-SQL in SQL Server 2000 and I have a table TRANSACTIONS which has a date column TRANDATE defined as DateTime, among many other columns which are irrelevant for this question.. The table is populated with transactions spanning many years. I ran into code, test, that has me confused. There is a simple SELECT , like this: SELECT TRANDATE, RECEIPTNUMBER FROM TRANSACTIONS WHERE TRANDATE BETWEEN '12/01/2010' and '12/31/2010' ORDER BY TRANDATE and its not returning two rows of data that I know are in that table. With the statement above, the last row its returning, in order, has a

Joining tables from different servers

Deadly 提交于 2019-11-27 15:08:49
Any suggestions how to join tables from different servers in stored procedure? Without more details, it's hard to give direct examples, but here is the basic idea: First, outside of the stored procedure, the host server (the server the stored procedure will be on) has to know about the second server, including (possibly) login information. On your main server, run the sp_addlinkedserver stored procedure. This only has to be done once: exec sp_addlinkedserver @server=’(your second server)‘; If you need to provide login information to this second server (for example, the process can't log in

SQL Server ROW_NUMBER() on SQL Server 2000?

假如想象 提交于 2019-11-27 14:48:13
I have a query that allows me to get records from a database table by giving it a minimum and maximum limit. It goes like this: SELECT T1.CDUSUARIO, T1.DSALIAS, T1.DSNOMBRE_EMPRESA, T1.DSCARGO, T1.DSDIRECCION_CORREO, T1.CDUSUARIO_ADMINISTRADOR, T1.FEMODIFICACION FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY CDUSUARIO) as row FROM TBL_USUARIOS ) as T1 WHERE row > @limiteInf and row <= @limiteSup ORDER BY DSALIAS ASC; Now, it works like heaven on SQL Server 2005 and SQL Server 2008 but tried to run it on an SQL Server 2000 database and says: ROW_NUMBER it's an unknown function name or something

How to execute SSIS package when a file is arrived at folder

青春壹個敷衍的年華 提交于 2019-11-27 14:27:51
The requirement is to execute SSIS package, when a file is arrived at a folder,i do not want to start the package manually . It is not sure about the file arrival timing ,also the files can arrive multiple times .When ever the files arrived this has to load into a table.I think, some solution like file watcher task ,still expect to start the package Peter_R The way I have done this in the past is with an infinite loop package called from SQL Server Agent, for example; This is my infinite loop package: Set 3 Variables: IsFileExists - Boolean - 0 FolderLocation - String - C:\Where the file is to

Query to get all foreign key constraints in SQL Server 2000

和自甴很熟 提交于 2019-11-27 14:14:53
问题 I need a query for SQL Server 2000 to get a list of all foreign keys. Particularly all the foreign keys that point to a particular column. How do I write this query? 回答1: select * from sysobjects where xtype = 'F' That should do the trick and be compatible with SQL Server 2000, I hope! If you additionally need the table and column information in SQL Server 2000, it gets a bit more involved; you need to join the sysforeignkeys and syscolumns catalog views like so: select so.name 'foreign key