sql-server-2000

How to get use text columns in a trigger

本秂侑毒 提交于 2019-11-28 10:49:31
问题 I am trying to use an update trigger in SQL Server 2000 so that when an update occurs, I insert a row into a history table, so I retain all history on a table: CREATE Trigger trUpdate_MyTable ON MyTable FOR UPDATE AS INSERT INTO [MyTableHistory] ( [AuditType] ,[MyTable_ID] ,[Inserted] ,[LastUpdated] ,[LastUpdatedBy] ,[Vendor_ID] ,[FromLocation] ,[FromUnit] ,[FromAddress] ,[FromCity] ,[FromProvince] ,[FromContactNumber] ,[Comment]) SELECT [AuditType] = 'U', D.* FROM deleted D JOIN inserted I

SQL update query syntax with inner join

我们两清 提交于 2019-11-28 10:44:26
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(CostCentre, 3, 1) = sCategoryCode AND substring(CostCentre, 5, 2) = sOperationCode The SET needs to

Get the time of a datetime using T-SQL?

◇◆丶佛笑我妖孽 提交于 2019-11-28 10:39:19
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? 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. In case of SQL Server, this should work SELECT CONVERT(VARCHAR(8),GETDATE(),108) AS HourMinuteSecond Try this SELECT CAST(DataField AS time(7)) AS 'time' http://msdn.microsoft.com/en-us/library/bb677243

SQL Server 2000: remove duplicates from comma-separated string

让人想犯罪 __ 提交于 2019-11-28 10:25:10
问题 I have been looking into this for a while now and I cannot find a way to remove duplicate strings from a comma-separated string in SQL Server 2000. I can find a lot of examples of this for SQL Server 2005 and 2008 but not 2000. Given the string test,test2,test,test3,test2 does anyone know how would you return test,test2,test3 ? 回答1: You can use while loop to parse the string and put the values you find in a temporary variable and before you add the value you do a check if it is already added.

Return the id of the just added row

牧云@^-^@ 提交于 2019-11-28 10:19:23
问题 In a similar vein to my previous question I again ask the SO guys for your collective wisdom and help. In a stored procedure and after passing some checks I need to insert a new row and return the newly created id for it. The check if a row exists works so it is the bit after that which I am undecided upon. The table has two important columns: The LocationID and the CaseID. The CaseID is autoincrementing, so when you add insert a new locationid it will automatically rachet up. I currently

How to connect to MSSQL 2000 from PHP 5.3 and up

孤街浪徒 提交于 2019-11-28 09:29:08
I have a legacy business application built on MS SQL Server 2000. I have some webbased utilities that access this database using PHP 5.2 with mssql extension. I need to reinstall the web server, and I looked forward to upgrade to PHP 5.4. Unfortunately, the mssql extension is not supported on PHP 5.3 and newer. There is the sqlsrv extension available form Microsoft , but the description says that it is only supported for accessing SQL server 2005 and up. How can I connect to my SQL Server 2000 from PHP 5.4 ? Did anyone already solve this issue ? This is a really complicated issue. Here are the

Weird SQL Server view definition

心已入冬 提交于 2019-11-28 09:19:01
问题 I've "inherited" a well over 10-year old app, and it does show its age at times. I've stumbled across a really weird view definition today - I just can't seem to make sense of it! Can you help me? This was originally on SQL Server 7.0 and has since been migrated to SQL Server 2005 - but obviously it's never been refactored / redone.... This is the view definition - based on a bunch of tables and another view: CREATE VIEW dbo.MyOddView AS SELECT t1.MVOID, t1.SomeOtherColumn, t2.Number , t3.OID

how to search Sql Server 2008 R2 stored procedures for a string?

别说谁变了你拦得住时间么 提交于 2019-11-28 09:10:39
I'm migrating a legacy SQLS2k to 2008R2, and it seems all data access was done through stored procs, and any custom queries use the legacy *= =* outer join syntax. There are upwards of a hundred procs so I don't want to open each one individually to see if it uses that syntax (most wouldn't), is there a way I can query the metadata for a list of procs/functions/views/triggers, then loop through searching for the *= or =* strings, printing out the name of the offending object? My background is oracle, I know how to find the metadata views there, but I'm a bit new to Sql Server. Downgrading the

Pass a variable into a trigger

蓝咒 提交于 2019-11-28 09:06:34
I have a trigger which deals with some data for logging purposes like so: CREATE TRIGGER trgDataUpdated ON tblData FOR UPDATE AS BEGIN INSERT INTO tblLog ( ParentID, OldValue, NewValue, UserID ) SELECT deleted.ParentID, deleted.Value, inserted.Value, @intUserID -- how can I pass this in? FROM inserted INNER JOIN deleted ON inserted.ID = deleted.ID END How can I pass in the variable @intUserID into the above trigger, as in the following code: DECLARE @intUserID int SET @intUserID = 10 UPDATE tblData SET Value = @x PS: I know I can't literally pass in @intUserID to the trigger, it was just used

SQL get the last date time record [duplicate]

末鹿安然 提交于 2019-11-28 08:55:06
This question already has an answer here: SQL Server: SELECT only the rows with MAX(DATE) 9 answers 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 |2012-02-14 12:14:20.997 |Closed | |dfg.txt |2013-02-14 12:20:59.407 |Open | +---------+------------------------+-------+ The