sql-server-2000

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

梦想与她 提交于 2019-11-27 01:52:33
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 need to do is to sort by the numbers in reverse order (e.g. in a.b.c.d, I need to sort by d,c,b,a to get the

ORDER BY DATE showing NULLS first then most recent dates

自古美人都是妖i 提交于 2019-11-27 01:39:16
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 I get the dates in the the order I want, but the NULL values are at the bottom of my result set. Is

Is there a way to get a list of all current temporary tables in SQL Server?

巧了我就是萌 提交于 2019-11-27 01:26:38
问题 I realize that temporary tables are session/connection bound and not visible or accessible out of the session/connection. I have a long running stored procedure that creates temporary tables at various stages. Is there a way I can see the list of current temporary tables? What privileges do I need to be able to do so? Alternatively, Is there a way I can see the particular SQL statement being executed inside a running stored procedure? The procedure is running as a scheduled job in SQL Server.

INSERT INTO @TABLE EXEC @query with SQL Server 2000

假如想象 提交于 2019-11-27 00:38:07
Is it true that SQL Server 2000, you can not insert into a table variable using exec? I tried this script and got an error message EXECUTE cannot be used as a source when inserting into a table variable. declare @tmp TABLE (code varchar(50), mount money) DECLARE @q nvarchar(4000) SET @q = 'SELECT coa_code, amount FROM T_Ledger_detail' INSERT INTO @tmp (code, mount) EXEC sp_executesql (@q) SELECT * from @tmp If that true, what should I do? N.B. - this question and answer relate to the 2000 version of SQL Server. In later versions, the restriction on INSERT INTO @table_variable ... EXEC ... were

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

主宰稳场 提交于 2019-11-27 00:05:15
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. KM. 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.name,c.name Or for more detail: SELECT s.name as ColumnName ,sh.name+'.'+o.name AS ObjectName ,o.type

WHERE IS NULL, IS NOT NULL or NO WHERE clause depending on SQL Server parameter value

为君一笑 提交于 2019-11-26 22:22:14
问题 I have a stored procedure in SQL Server 2000 that performs a search based on parameter values. For one of the parameters passed in, I need a different WHERE clause depending on its value - the problem is that the 3 values would be where MyColumn IS NULL IS NOT NULL ANY VALUE (NULL AND NOT NULL) (essentially no WHERE clause) I'm having some mental block in coming up with the correct syntax. Is this possible to do in one select statement without performing some IF @parameter BEGIN ... END

SQL: Group By on Consecutive Records

五迷三道 提交于 2019-11-26 20:40:35
问题 A slightly tricky SQL question (we are running SQL server 2000). I have the following table, StoreCount - WeekEndDate StoreCount 2010-07-25 359 2010-07-18 359 2010-07-11 358 2010-07-04 358 2010-06-27 358 2010-06-20 358 2010-06-13 358 2010-06-06 359 2010-05-30 360 2010-05-23 360 2010-05-16 360 I want to turn this into the following output - StartDate EndDate StoreCount 2010-07-18 2010-07-25 359 2010-06-13 2010-07-11 358 2010-06-06 2010-06-06 359 2010-05-16 2010-05-30 360 As you can see, I'm

TSQL - Is it possible to define the sort order?

不打扰是莪最后的温柔 提交于 2019-11-26 19:36:16
问题 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. 回答1: 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

Regular Expressions in SQL Server servers?

拜拜、爱过 提交于 2019-11-26 18:56:15
Is it possible to make efficient queries that use the complete regular expression feature set. If not Microsoft really should consider that feature. For SQL Server 2000 (and any other 32 bit edition of SQL Server), there is xp_pcre , which introduces Perl compatible regular expressions as a set of extended stored procedures. I've used it, it works. The more recent versions give you direct access to the .NET integrated regular expressions (this link seems to be dead, here is another one: MSDN: How to: Work with CLR Database Objects ). The answer is no, not in the general case, although it might

Joining tables from different servers

前提是你 提交于 2019-11-26 18:29:42
问题 Any suggestions how to join tables from different servers in stored procedure? 回答1: 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)