sql-server

Using SqlDependency with named Queues

我只是一个虾纸丫 提交于 2021-02-18 10:41:10
问题 I have the following code that uses SqlDependency to monitor changes in one of my databases It works great, except every run it generates its own Queue/Service/Route with a guid in the database: Class: class SqlWatcher { private string connectionString; private string sqlQueue; private string listenerQuery; private SqlDependency dependency; public SqlWatcher(string connectionString, string sqlQueue, string listenerQuery) { this.connectionString = connectionString; this.sqlQueue = sqlQueue;

execute result of select statement

淺唱寂寞╮ 提交于 2021-02-18 10:20:10
问题 How can I execute the results of my select query. The query below gives me some SQL statements back as result. I want to execute does statements, how to do this? All this is executed in SQL Sever Management Studio. Query: SELECT 'UPDATE Rolecopy SET PartofFT = ''' + R2.PlayedbyOT + ''', OriginalOT = ''' + R.PlayedbyOT + ''' WHERE RoleNo = ' + CAST(R.RoleNo AS VARCHAR) + CHAR(13) FROM Role R INNER JOIN Role R2 ON R.PartofFT = R2.PartofFT AND R.RoleNo <> R2.RoleNo WHERE EXISTS ( SELECT PG

Sql Server union with If condition

♀尐吖头ヾ 提交于 2021-02-18 09:33:52
问题 I have a query like: DECLARE @tmpValue SET @tmpValue = 0 -- it will be change SELECT * FROM Animal WHERE AniActive = 1 UNION IF @tmpValue > 0 SELECT * FROM Animal WHERE.Active = 0 When I use like this it is giving error because of if condition. I have to use UNION because of our structure. How can I use it with if condition? Thanks, John 回答1: Move the condition @tmpValue > 0 to the WHERE clause like so: SELECT * FROM Animal WHERE AniActive = 1 UNION SELECT * FROM Animal WHERE @tmpValue > 0

Sql Server union with If condition

天涯浪子 提交于 2021-02-18 09:31:33
问题 I have a query like: DECLARE @tmpValue SET @tmpValue = 0 -- it will be change SELECT * FROM Animal WHERE AniActive = 1 UNION IF @tmpValue > 0 SELECT * FROM Animal WHERE.Active = 0 When I use like this it is giving error because of if condition. I have to use UNION because of our structure. How can I use it with if condition? Thanks, John 回答1: Move the condition @tmpValue > 0 to the WHERE clause like so: SELECT * FROM Animal WHERE AniActive = 1 UNION SELECT * FROM Animal WHERE @tmpValue > 0

Sql Server union with If condition

旧时模样 提交于 2021-02-18 09:31:11
问题 I have a query like: DECLARE @tmpValue SET @tmpValue = 0 -- it will be change SELECT * FROM Animal WHERE AniActive = 1 UNION IF @tmpValue > 0 SELECT * FROM Animal WHERE.Active = 0 When I use like this it is giving error because of if condition. I have to use UNION because of our structure. How can I use it with if condition? Thanks, John 回答1: Move the condition @tmpValue > 0 to the WHERE clause like so: SELECT * FROM Animal WHERE AniActive = 1 UNION SELECT * FROM Animal WHERE @tmpValue > 0

Disabling SSIS Package Validation when Loading a Package in the VS Designer

╄→гoц情女王★ 提交于 2021-02-18 09:02:46
问题 I have a few SSIS packages that are deployed to a SQL 2005 Server and are subsequently designed and maintained in Visual Studio 2003. When I open any of the BIDS projects, followed by one of the packages, the designer always validates every Data Flow and Task object. Usually, this isn't a problem. However, under certain circumstances a system account that we use for connecting and export data from an AS400 will not validate properly. Since I'm exporting a TON of tables, each Data Flow object

Laravel connect to a SQL Server 2008 named instance

回眸只為那壹抹淺笑 提交于 2021-02-17 22:55:35
问题 I am trying to connect an SQL server from an Ubuntu machine, everythings works great except for named instances: this works 'data' => array( 'driver' => 'sqlsrv', 'host' => 'xxxx', 'port' => 1433, 'database' => 'db', 'username' => 'user', 'password' => 'pwd', 'prefix' => '', ), this doesn't 'data' => array( 'driver' => 'sqlsrv', 'host' => 'yyyy\NAMEDINSTANCE', 'port' => 1433, 'database' => 'db', 'username' => 'user', 'password' => 'pwd', 'prefix' => '', ), I always end up with this error:

MERGE - conditional “WHEN MATCHED THEN UPDATE”

梦想的初衷 提交于 2021-02-17 21:14:10
问题 The highlights in the image below shows the logic I want to implement. I realize the syntax is incorrect. Is there a way to conditionally update a record in a MERGE statement only if it the value of one of its columns in the target table is NULL, and the corresponding value in the source table is not null? How would you suggest re-writing this? MERGE dbo.input_311 AS [t] USING dbo.input_311_staging AS [s] ON ([t].[unique key] = [s].[unique key]) WHEN NOT MATCHED BY TARGET THEN INSERT(t.

Sql Server Management Studio Object Explorer disappeared - missing - vanished

☆樱花仙子☆ 提交于 2021-02-17 21:10:45
问题 The SQL Server Management Studio Object Explorer menu disappeared. The shortcut F8 and the view->object explorer method neither do anything. I have clicked everything on the keyboard, googled around, but nothing. I really need this back, it's a massive hassle having to navigate through the summary window without the object explorer tree view! 回答1: I just had this, and the menu option... Window > Reset Window Layout ...worked a treat. 回答2: I have seen this same problem when double-clicking on

Sql Server Management Studio Object Explorer disappeared - missing - vanished

梦想的初衷 提交于 2021-02-17 21:09:56
问题 The SQL Server Management Studio Object Explorer menu disappeared. The shortcut F8 and the view->object explorer method neither do anything. I have clicked everything on the keyboard, googled around, but nothing. I really need this back, it's a massive hassle having to navigate through the summary window without the object explorer tree view! 回答1: I just had this, and the menu option... Window > Reset Window Layout ...worked a treat. 回答2: I have seen this same problem when double-clicking on