sql-server-2005

SQL - Order by with alphanumeric characters

一个人想着一个人 提交于 2019-12-19 09:22:02
问题 I have the following table: create table #tbl ( product_id nvarchar(50) ) insert into #tbl values ('011014-A11') insert into #tbl values ('011014-A10') insert into #tbl values ('011014') insert into #tbl values ('011014-A1') insert into #tbl values ('011014-A2') I want to order the Product IDs like this (from the smallest to the greatest): 011014 011014-A1 011014-A2 011014-A10 011014-A11 This is what I tried, but it is not working: select product_id from #tbl order by product_id desc How do I

undo changes to a stored procedure

一世执手 提交于 2019-12-19 09:21:01
问题 I altered a stored procedure and unknowingly overwrote some changes that were made to it by another developer. Is there a way to undo the changes and get the old script back? Unfortunately I do not have a backup of that database, so that option is ruled out. 回答1: The answer is YES , you can get it back, but it's not easy. All databases log every change made to it. You need to: Shutdown the server (or at least put it into read-only mode) Take a full back up of the server Get a copy of all the

Hirarchical sorting in sql server when child id contains '.'

半城伤御伤魂 提交于 2019-12-19 09:08:04
问题 i have some childid like below childid ------------ 1.1 1.2 2.8 2.7 6.5 6.5.1 6.5.15 7.1 8 sort order will be childid -------- 1.1 1.2 2.7 2.8 6.5 6.51 6.5.15 7.1 i tried to converted to intiger like below declare @str nvarchar(max)='1.23.2'; set @str=(select replace(@str,'.','')) select @str but it fails when 7.1 8 comes it gives order like 8 7.1 but i need order like below 7.1 8 also if number like 7.1.1 7.1.8 6.7.7.7 then order should be 6.7.7.7 7.1.1 7.1.8 i hope somebody can help me to

Is there something like the FileSystemWatcher for Sql Server Tables?

拟墨画扇 提交于 2019-12-19 09:02:26
问题 i would like my windows service (to be written in .NET) to recognize when new rows are added to a specific table, but instead of pulling the data from the sql-server i would like to use a server push model. does somebody has a hint for me how to achieve this? i am using sql server 2005. tia 回答1: There's also the ADO.NET SqlDependency mechanism if you're using client side ADO.NET with C# or VB.NET A SqlDependency object can be associated with a SqlCommand in order to detect when query results

SQL SERVER NON-Clustered Index on table variable?

筅森魡賤 提交于 2019-12-19 08:12:56
问题 How can we create non-clustered index on table variable? Create Table @risk (rskid int) Create nonclustered index r_rskid_nc on @risk(rskid) It does not work?? My proc How can i optimize it ?? ALTER PROCEDURE [dbo].[SPR_LV004] ( @TopN INT ,@LoggedUserId INT ,@Entity VARCHAR(255) ,@OpModel VARCHAR(255) ,@RiskCat VARCHAR(255) ,@RsdlInh VARCHAR(1) ,@DisplayAction VARCHAR(1) ,@LastAssDate DATETIME ) AS SET NOCOUNT ON DECLARE @Thisdate DATETIME SET @ThisDate = GETDATE() DECLARE @MainFilter TABLE(

SQL Server: Find out what row caused the TSQL to fail (SSIS)

守給你的承諾、 提交于 2019-12-19 08:12:40
问题 SQL Server 2005 Question: I'm working on a data conversion project where I'm taking 80k+ rows and moving them from one table to another. When I run the TSQL, it bombs with various errors having to do with converting types, or whatever. Is there a way to find out what row caused the error? ===================== UPDATE: I'm performing an INSERT INTO TABLE1 (...) SELECT ... FROM TABLE2 Table2 is just a bunch of varchar fields where TABLE1 has the right types. This script will be put into a sproc

Persisting a computed datetime column in SQL Server 2005

。_饼干妹妹 提交于 2019-12-19 08:06:27
问题 I have an XML column in a table; I want to "promote" a certain value in that XML as a computed column and index it for faster searching. I have a function that takes in the XML information and outputs the element of interest, like this: CREATE FUNCTION [dbo].[fComputeValue] (@data XML) RETURNS datetime WITH SCHEMABINDING AS BEGIN RETURN @data.value('(/Metadata/Value[@Key="StartDate"])[1]', 'datetime') END However when I try to create the computed column: ALTER TABLE dbo.CustomMetadataTable

SQL Server : Rollback without BEGIN TRANSACTION

戏子无情 提交于 2019-12-19 07:52:08
问题 Is there a way we can rollback to previous state of the transaction using ROLLBACK without BEGIN TRANSACTION ? delete from table1; ROLLBACK Message: The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. Any input would be of great help. Thanks !!! 回答1: To expand on gerrytans answer when you explicitly set IMPLICIT_TRANSACTIONS ON, you can use a ROLLBACK. See the MSDN doco related to this. Note that this isn't the default autocommit transaction mode. This allows me to run a

Concat two column in a select statement sql server 2005

六眼飞鱼酱① 提交于 2019-12-19 07:51:44
问题 How to Concat two column in a select statement sql server 2005? Here is my statement Select FirstName,secondName from Table ... Now i did try concating secondName with FirstName by using Select FirstName + ' ' + secondName from Table But some values are NULL in secondName column for some records.. My select statement returns NULL instead of FirstName .. I want to have FirstName if secondName is NULL .. 回答1: SELECT FirstName + ISNULL(' ' + SecondName, '') from Table 回答2: If one of your fields

SQL: Why are NULL values filtered out within this where clause?

别来无恙 提交于 2019-12-19 07:35:54
问题 In my table, I have a nullable bit column (legacy system...) and another developer recently made a change to a stored procedure to only show values where the bit column was not true (1). Because this is a nullable column, we noticed that if the column was NULL, the record was not being picked up. WHY is this? Both the other developer and I agree that NULL <> 1... Is this a bug in SQL or was this designed this way? Seems like a design flaw. Current Code: (VoidedIndicator <> 1) Proposed Fix: