sql-server-2008-r2

Search XML with a LIKE or similar full search operation

十年热恋 提交于 2019-12-03 09:39:58
I want to search an XML valued column to see if a contains a string. I don't know the schema, I want to know if the string is contained anywhere at all. I don't know if XPATH would work in this situation. The equivalent of Select s.Name, ts.ValueXML from table t (nolock) join table2 ts (nolock) on t.key_Id = ts.key_Id join table3 s (nolock) on ts.key_Id=s.key_Id where s.Name like '%Lab%' and ts.ValueXML like '%PreviewDateRange%' ERROR: Argument data type xml is invalid for argument 1 of like function. relevant ts Table columns ValueXml (XML(.), null) The item I'm searching for should be an

How to refresh the data on other user's interface when some user edits the data

跟風遠走 提交于 2019-12-03 08:54:35
In a VB.net application I have a SQL interface, I have a users table in the SQL database for users of this application, all of them see the same data now when a user clicks a button changes are saved in the sql and data is refreshed for that user, however I want the data to be refreshed for all users as soon as some user clicks that button. Ideas I have refreshing data every second, which is not good SQL trigger to vb.net which I need more clarification about! What would be the most effective way? i would like a work around without timers! Thanks SQL Server Notification Services SQL provides

Entity Framework 4 Stored Procedure Call Timing Out

时光总嘲笑我的痴心妄想 提交于 2019-12-03 08:50:56
问题 I have a stored procedure imported into EF4, and when I call it with certain parameters after 30 seconds it throws a time out error. In SQL Server profiler I can see the stored procedure call with the proper parameters taking just over 30 seconds, which is the timeout on my application. HOWEVER when I execute the same SQL sent to the profiler in Query Analyzer it executes sub-second. What could cause this discrepancy between being called from EF and being called from SQL Server Management

Using the “With Clause” SQL Server 2008

被刻印的时光 ゝ 提交于 2019-12-03 08:33:42
问题 Can someone show me a sample SQL server script that I can look at that uses the "With Clause" ? I am trying to use this clause to iterate through 200 databases that contain the same table that I am trying to run a query on. I am trying to avoid using a cursor because the query time takes too long as well as using a while a loop. Can someone advise me as to what I can do. Thank you. 回答1: Just a poke, but here's another way to write FizzBuzz :) 100 rows is enough to show the WITH statement, I

Powershell Invoke-sqlcmd keeping connection open and trying to reuse it

半腔热情 提交于 2019-12-03 08:29:14
I have a Powershell script that uses invoke-sqlcmd to apply scripts to a series of development databases. I loop through a list of scripts and compare it to the current release level of the database and then apply the required scripts to get the DB to the release level it needs to be at. Certain databases are reference databases and are in a READ_ONLY state. I connect to those database run an alter DB script setting them to READ_WRITE apply the script then change the back to READ_ONLY. Overall the script works well, the issue is it looks like when PowerShell first opens a connection to the

What is the syntax meaning of RAISERROR()

删除回忆录丶 提交于 2019-12-03 08:08:05
问题 I just created a Instead After Trigger whose syntax is given below: Create trigger tgrInsteadTrigger on copytableto Instead of Insert as Declare @store_name varchar(30); declare @sales int; declare @date datetime; select @store_name = i.store_name from inserted i select @sales = i.sales from inserted i select @date = i.Date from inserted i begin if (@sales > 1000) begin RAISERROR('Cannot Insert where salary > 1000',16,1); ROLLBACK; end else begin insert into copytablefrom(store_name, sales,

Programmatically copy indexes from one table to another in SQL Server

六眼飞鱼酱① 提交于 2019-12-03 07:24:52
问题 Basically the exact same question as in this question: How to copy indexes from one table to another in SQL Server, BUT, how do I do it programmatically in T-SQL, given a source table name and destination table name? I.e. without knowing what table up front. I can copy the basic structure SELECT TOP (0) * INTO [BackupTable] FROM [OriginalTable] But that doesn't copy indexes, constraints, triggers etc I ideally would like a stored proc that looks something like: spCloneTableStructure

SQL to remove rows with duplicated value while keeping one

寵の児 提交于 2019-12-03 07:24:30
问题 Say I have this table id | data | value ----------------- 1 | a | A 2 | a | A 3 | a | A 4 | a | B 5 | b | C 6 | c | A 7 | c | C 8 | c | C I want to remove those rows with duplicated value for each data while keeping the one with the min id, e.g. the result will be id | data | value ----------------- 1 | a | A 4 | a | B 5 | b | C 6 | c | A 7 | c | C I know a way to do it is to do a union like: SELECT 1 [id], 'a' [data], 'A' [value] INTO #test UNION SELECT 2, 'a', 'A' UNION SELECT 3, 'a', 'A'

Unable to access sql server configuration manager

假装没事ソ 提交于 2019-12-03 07:15:00
问题 I installed the evaluation version of SQL Server 2008 R2 after removing SQL Server 2008 R2 Express. SQL Server Configuration manager was still accessible after the un-installation but now it is no longer accessible with this error: Cannot connect to WMI provider. You do not have permission or the server is unreachable. Note that you can only manage SQL Server 2005 servers with SQL Server Configuration Manager. Invalid class [0x80041010] The file sqlmgmproviderxpsp2up.mof is found in the

How to list role members in SQL Server 2008 R2

浪子不回头ぞ 提交于 2019-12-03 06:57:31
问题 I'm using the following T-SQL to obtain role members from my SQL Server 2008 R2 database: select rp.name as database_role, mp.name as database_user from sys.database_role_members drm join sys.database_principals rp on (drm.role_principal_id = rp.principal_id) join sys.database_principals mp on (drm.member_principal_id = mp.principal_id) order by rp.name When I examine the output I notice that the only role members listed for db_datareader are db roles - no user members of db_datareader are