sql-server-2005

SQL Server table creation date query

懵懂的女人 提交于 2019-12-17 15:24:21
问题 How can I get the table creation date of a MS SQL table using a SQL query? I could not see any table physically but I can query that particular table. 回答1: For 2005 up, you can use SELECT [name] ,create_date ,modify_date FROM sys.tables I think for 2000, you need to have enabled auditing. 回答2: For SQL Server 2005 upwards: SELECT [name] AS [TableName], [create_date] AS [CreatedDate] FROM sys.tables For SQL Server 2000 upwards: SELECT so.[name] AS [TableName], so.[crdate] AS [CreatedDate] FROM

Can I save an 'Object' in a SQL Server database?

≯℡__Kan透↙ 提交于 2019-12-17 15:23:17
问题 I want to save an object (of any type) into a field in a database in SQL Server 2005. Is it possible? Do I have to convert the object into something, like a byte array for example and cast it back when retrieving it? 回答1: You can use the VARBINARY(MAX) field type in SQL Server, if you like. You can store any type of object in there, up to 2 GB in size. To access it, you can use ADO.NET - something like this: object yourMysteryObject = (whatever you like it to be); MemoryStream memStream = new

SQL Server - where is “sys.functions”?

别来无恙 提交于 2019-12-17 15:21:48
问题 SQL Server 2005 has great sys.XXX views on the system catalog which I use frequently. What stumbles me is this: why is there a "sys.procedures" view to see info about your stored procedures, but there is no "sys.functions" view to see the same for your stored functions? Doesn't anybody use stored functions? I find them very handy for e.g. computed columns and such! Is there a specific reason sys.functions is missing, or is it just something that wasn't considered important enough to put into

SQL same unit between two tables needs order numbers in 1 cell

馋奶兔 提交于 2019-12-17 14:54:00
问题 I have 2 tables: SELECT UnitId FROM dbo.tblUnits SELECT UnitId, WorkOrderNumber FROM dbo.tblWorkOrders I need to display all UnitId's from dbo.tblUnits then in 1 column diplay all the WorkOrders seperated by a comma. So here is some sample data: dbo.tblUnits: UnitId 123 156 178 dbo.tblWorkOrders UnitId WorkOrderNumber 123 1 123 2 156 4 178 5 178 9 178 10 I have to use the tblUnits table because I am pulling more data from it but the final result I want to show this: UnitId WorkOrderNumber 123

SQL same unit between two tables needs order numbers in 1 cell

假如想象 提交于 2019-12-17 14:53:46
问题 I have 2 tables: SELECT UnitId FROM dbo.tblUnits SELECT UnitId, WorkOrderNumber FROM dbo.tblWorkOrders I need to display all UnitId's from dbo.tblUnits then in 1 column diplay all the WorkOrders seperated by a comma. So here is some sample data: dbo.tblUnits: UnitId 123 156 178 dbo.tblWorkOrders UnitId WorkOrderNumber 123 1 123 2 156 4 178 5 178 9 178 10 I have to use the tblUnits table because I am pulling more data from it but the final result I want to show this: UnitId WorkOrderNumber 123

Sql Server : How to use an aggregate function like MAX in a WHERE clause

淺唱寂寞╮ 提交于 2019-12-17 10:59:00
问题 I want get the maximum value for this record. Please help me: SELECT rest.field1 FROM mastertable AS m INNER JOIN ( SELECT t1.field1 field1, t2.field2 FROM table1 AS T1 INNER JOIN table2 AS t2 ON t2.field = t1.field WHERE t1.field3=MAX(t1.field3) -- ^^^^^^^^^^^^^^ Help me here. ) AS rest ON rest.field1 = m.field 回答1: You could use a sub query... WHERE t1.field3 = (SELECT MAX(st1.field3) FROM table1 AS st1) But I would actually move this out of the where clause and into the join statement, as

Should I use SQL_Variant data type?

落花浮王杯 提交于 2019-12-17 10:57:38
问题 using SQL Server 2005 with SP4 and I am designing a database table. Here is the table DDL CREATE TABLE CPSync4D.ProjectProfilerOption ( ProjectProfilerOptionID INT IDENTITY(1,1) CONSTRAINT PK_ProjectProfilerOption_ProjectProfilerOptionID PRIMARY KEY ,ProjectID INT CONSTRAINT FK_ProjectProfilerOption_Project_ProjectID FOREIGN KEY(ProjectID) REFERENCES CPSync4D.Project(ProjectID) ON DELETE CASCADE ,ProfilerOptionID TINYINT CONSTRAINT FK_ProjectProfilerOption_ProfilerOption_ProfilerOptionID

DECODE( ) function in SQL Server

£可爱£侵袭症+ 提交于 2019-12-17 10:57:08
问题 SELECT PC_COMP_CODE, 'R', PC_RESUB_REF, DECODE(PC_SL_LDGR_CODE, '02', 'DR', 'CR'), PC_DEPT_NO DEPT, '', --PC_DEPT_NO, PC_SL_LDGR_CODE + '/' + PC_SL_ACNO, SUM(DECODE(PC_SL_LDGR_CODE, '02', 1, -1) * PC_AMOUNT), PC_CHEQUE_NO CHQNO FROM GLAS_PDC_CHEQUES WHERE PC_RESUB_REF IS NOT NULL AND PC_DISCD NOT IN ('d', 'D', 'T') GROUP BY PC_RESUB_REF, PC_COMP_CODE, 'JJ', PC_SL_LDGR_CODE + '/' + PC_SL_ACNO, PC_DEPT_NO, PC_CHEQUE_NO, DECODE(PC_SL_LDGR_CODE, '02', 'DR', 'CR') Above is a Oracle query; how can

Auditing SQL Server data changes

限于喜欢 提交于 2019-12-17 10:51:37
问题 I'm looking at changing our Auditing process for our SQL Server 2005 databases and I came across Change Data Capture in SQL Server 2008. This looks like a good idea, and I'm tempted to try it, but before I do has anyone used it in a commercial environment and what are your thoughts? I noticed when I was reading about CDC in the MS help, it said that audit data would usually be kept for a couple of days. That's not possible here, I'd like to keep the data indefinitely, does anyone know of

Why do SQL Server Scalar-valued functions get slower?

妖精的绣舞 提交于 2019-12-17 10:35:09
问题 Why do Scalar-valued functions seem to cause queries to run cumulatively slower the more times in succession that they are used? I have this table that was built with data purchased from a 3rd party. I've trimmed out some stuff to make this post shorter... but just so you get the idea of how things are setup. CREATE TABLE [dbo].[GIS_Location]( [ID] [int] IDENTITY(1,1) NOT NULL, --PK [Lat] [int] NOT NULL, [Lon] [int] NOT NULL, [Postal_Code] [varchar](7) NOT NULL, [State] [char](2) NOT NULL,