sql-server-2008-r2

SQL Server Query to Count Value Every 06:30

一曲冷凌霜 提交于 2020-02-29 09:13:08
问题 please help me. I am having problem with my data and my query. Please look at my table design first. CREATE TABLE [dbo].[my_table]( [ID] [int] NOT NULL, [date] [datetime] NULL, [value] [int] NULL, [product_code] [varchar](50) NULL, [expectedvalue] [int] NULL, CONSTRAINT [PK_my_table] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO And this is the data, all

Is it possible to modify system stored procedure?

瘦欲@ 提交于 2020-02-27 08:22:37
问题 I would like to alter sp_helpindex system procedure, or rather replace it with my version. The reasons are: show index_id show included columns show filter definition show fill factor show index sizes show heap info as well Also, interestingly enough my version turned out to be better performing (faster, fewer reads, no cursor). I tried the following, but none of these worked: sp_rename alter procedure drop procedure The error Invalid object name 'sys.sp_helpindex'. The only option I can

Fate of an ADO.Net Transaction when connection is suddenly broken

久未见 提交于 2020-02-15 08:30:42
问题 Consider the sample code below. If the connection to the database is suddenly broken when on STEP 2 (i.e. 2nd command), then even if we try to rollback the transaction it will not rollback since there is no connection to the database server. In such a case, what happens to the transaction object on the database server side? Will it remain in a waiting mode? I have had this situation come up when I tried to run a long transaction in ADO.Net by connecting to database servers through a VPN

Fate of an ADO.Net Transaction when connection is suddenly broken

纵然是瞬间 提交于 2020-02-15 08:28:26
问题 Consider the sample code below. If the connection to the database is suddenly broken when on STEP 2 (i.e. 2nd command), then even if we try to rollback the transaction it will not rollback since there is no connection to the database server. In such a case, what happens to the transaction object on the database server side? Will it remain in a waiting mode? I have had this situation come up when I tried to run a long transaction in ADO.Net by connecting to database servers through a VPN

Calling an in-line TVF with named parameters, what is the proper syntax?

孤街醉人 提交于 2020-02-11 13:30:51
问题 I tried calling an in-line TVF with positional parameters and it works fine: SELECT MyTable.Col1, (SELECT TvfColumn FROM ufnGetData(MyTable.Col1, MyTable.Col2)), MyTable.Col2 FROM MyTable Then I tried to name the parameters to the TVF and it does not parse: SELECT MyTable.Col1, (SELECT TvfColumn FROM ufnGetData(@Param1=MyTable.Col1, @Param2=MyTable.Col2)), MyTable.Col2 FROM MyTable The function looks something like: CREATE FUNCTION dbo.ufnGetData ( @Param1 INT, @Param2 INT ) RETURNS TABLE AS

Use a trigger in SQL Server 2008 R2 to change the value of one column based on the value of another column during update

夙愿已清 提交于 2020-02-08 02:45:17
问题 I need to change the value of a column when a record is updated, based on the value of another column in the same table. The legacy application updating the table cannot be re-coded to handle this. The basic logic would be: If DateShipped is not null, set OrderLocation = 4 Hoping I can do this at the database level with an update trigger in SQL Server 2008 R2. thank you. 回答1: CREATE TRIGGER tr_OrderLocation_Update ON TableName FOR UPDATE,INSERT BEGIN SET NOCOUNT ON; UPDATE t SET t

PATINDEX with SOUNDEX

女生的网名这么多〃 提交于 2020-02-07 04:41:07
问题 Want to search the string using PATINDEX and SOUNDEX. I have the following table with some sample data to search the given string using PATINDEX and SOUNDEX . create table tbl_pat_soundex ( col_str varchar(max) ); insert into tbl_pat_soundex values('Smith A Steve'); insert into tbl_pat_soundex values('Steve A Smyth'); insert into tbl_pat_soundex values('A Smeeth Stive'); insert into tbl_pat_soundex values('Steve Smith A'); insert into tbl_pat_soundex values('Smit Steve A'); String to search:-

How to Restore data from MS SQL 2012 to MS SQL 2008 using .bak file. Is this Possible?

北战南征 提交于 2020-02-06 06:52:07
问题 I have a requirement that am facing difficulty i.e. restoring a data from MS SQL 2012 to MS SQL 2008 using .bak file. when am trying to restore , am getting an error. is this possibility to restore this to downgrade. can any one help me how to restore ? 回答1: Unfortunately SQL Server will not go backwards. The only way you can do this is Using SSIS to transfer the data or you can use the import/export utility. On your 2012 Server Right click on the DB you want to export data from and scroll

Cannot resolve the collation conflict between “Latin1_General_CI_AI” and “SQL_Latin1_General_CP1_CI_AS” in the equal to operation

霸气de小男生 提交于 2020-02-05 03:26:05
问题 I am trying to create a procedure in SQL Server 2008R2 but it is showing this error Cannot resolve the collation conflict between "Latin1_General_CI_AI" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation. The procedure that I have created is CREATE Procedure Ps_Quiz_OnlineTest_QuestionsWithOptions_Get --'Ques1' @Ques Varchar(8000) As Begin Select A.QuestionId, A.QsnDesc, A.CorrectOption, B.OptionValue, A.Marks, ( Select QsnName From Quiz_tblQsnsLimitMaster Where QsnId = @Ques)

golang SQL Server query via go-mssqldb

妖精的绣舞 提交于 2020-02-04 09:46:48
问题 I'm trying to query SQL Server 2008 R2 using go https://github.com/denisenkom/go-mssqldb. The SQL Server 2008 R2 instance is on a VM under Windows Server 2008 R2; I'm doing the development under the Win 7 VMWare host and running the program from there to query the DB on the VM. The DB has been up and running an app hosted on the server VM. Code is below. The error I'm getting is : [EDIT 2017-03-14 : new error when I specify port] Login error: read tcp 192.168.91.1:15222->192.168.91.135:1433: