sql-server-2000

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

亡梦爱人 提交于 2019-11-26 10:30:24
问题 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 ) 回答1: 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

How Can I Sort A 'Version Number' Column Generically Using a SQL Server Query

落花浮王杯 提交于 2019-11-26 09:48:52
问题 I wonder if the SQL geniuses amongst us could lend me a helping hand. I have a column VersionNo in a table Versions that contains \'version number\' values like VersionNo --------- 1.2.3.1 1.10.3.1 1.4.7.2 etc. I am looking to sort this, but unfortunately, when I do a standard order by , it is treated as a string, so the order comes out as VersionNo --------- 1.10.3.1 1.2.3.1 1.4.7.2 Intead of the following, which is what I am after: VersionNo --------- 1.2.3.1 1.4.7.2 1.10.3.1 So, what I

ORDER BY DATE showing NULLS first then most recent dates

﹥>﹥吖頭↗ 提交于 2019-11-26 09:43:43
问题 I have a stored procedure which executes a select statement. I would like my results ordered by a date field and display all records with NULL dates first and then the most recent dates. The statement looks like this: SELECT a,b,c,[Submission Date] FROM someView ORDER BY [Submission Date] ASC Now this will display all records with NULL Submission Dates first, but when I get to rows that have date values in them, they are not the most recent dates in the view. If I replace ASC with DESC, then

How to get the first and last date of the current year?

随声附和 提交于 2019-11-26 09:22:18
问题 Using SQL Server 2000, how can I get the first and last date of the current year? Expected Output: 01/01/2012 and 31/12/2012 回答1: SELECT DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) AS StartOfYear, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, -1) AS EndOfYear The above query gives a datetime value for midnight at the beginning of December 31. This is about 24 hours short of the last moment of the year. If you want to include time that might occur on December 31, then you should compare to the

SQL Server: How to Join to first row

半世苍凉 提交于 2019-11-26 09:21:10
I'll use a concrete, but hypothetical, example. Each Order normally has only one line item : Orders: OrderGUID OrderNumber ========= ============ {FFB2...} STL-7442-1 {3EC6...} MPT-9931-8A LineItems: LineItemGUID Order ID Quantity Description ============ ======== ======== ================================= {098FBE3...} 1 7 prefabulated amulite {1609B09...} 2 32 spurving bearing But occasionally there will be an order with two line items: LineItemID Order ID Quantity Description ========== ======== ======== ================================= {A58A1...} 6,784,329 5 pentametric fan {0E9BC...} 6

How to find column names for all tables in all databases in SQL Server

一笑奈何 提交于 2019-11-26 09:18:22
问题 I want to find all column names in all tables in all databases . Is there a query that can do that for me? The database is Microsoft SQL Server 2000. 回答1: Try this: select o.name,c.name from sys.columns c inner join sys.objects o on c.object_id=o.object_id order by o.name,c.column_id With resulting column names this would be: select o.name as [Table], c.name as [Column] from sys.columns c inner join sys.objects o on c.object_id=o.object_id --where c.name = 'column you want to find' order by o

Query extremely slow in code but fast in SSMS

不羁的心 提交于 2019-11-26 06:45:54
问题 I have a fairly simple query that I keep getting timeouts (it takes over three minutes to complete, I stopped it early so I could post this question) on when it is running in code, however when I run the same query from the same computer in Sql Server Management Studio the query will only take 2532 ms the first query when the data is not cached on the server and 524 ms for repeated queries. Here is my c# code using (var conn = new SqlConnection(\"Data Source=backend.example.com;Connect

Pivot using SQL Server 2000

六眼飞鱼酱① 提交于 2019-11-26 04:52:55
问题 I put together a sample scenario of my issue and I hope its enough for someone to point me in the right direction. I have two tables Products Product Meta I need a result set of the following 回答1: We've successfully used the following approach in the past... SELECT [p].ProductID, [p].Name, MAX(CASE [m].MetaKey WHEN 'A' THEN [m].MetaValue END) AS A, MAX(CASE [m].MetaKey WHEN 'B' THEN [m].MetaValue END) AS B, MAX(CASE [m].MetaKey WHEN 'C' THEN [m].MetaValue END) AS C FROM Products [p] INNER

How to create the linked server for SQL Server 2008 where we have the database from 2000 and 2005

和自甴很熟 提交于 2019-11-26 04:23:58
问题 Currently I am working on SQL Server 2000,2005 & 2008, my requirement is like, the database available in SQL Server 2000 & 2005 will be available in 2008 using a linked server. Let\'s say I have a database in SQL Server 2000 called LIVE_2000 and in SQL Server 2005 it\'s called LIVE_2005 , can someone please help me to create the linked server for LIVE_2000 and LIVE_2005 into SQL Server 2008? 1st thing is this even possible? Thanks in advance...` 回答1: There are a few different ways that you

Find index of last occurrence of a sub-string using T-SQL

最后都变了- 提交于 2019-11-26 04:21:06
问题 Is there a straightforward way of finding the index of the last occurrence of a string using SQL? I am using SQL Server 2000 right now. I basically need the functionality that the .NET System.String.LastIndexOf method provides. A little googling revealed this - Function To Retrieve Last Index - but that does not work if you pass in a \"text\" column expression. Other solutions found elsewhere work only so long as the text you are searching for is 1 character long. I will probably have to cook