sql-server-2008-r2

sp_send_dbmail - formatting row in table as red for an alert

半腔热情 提交于 2019-11-30 19:58:15
问题 I'm using something similar to example C on this MSDN page: http://msdn.microsoft.com/en-us/library/ms190307.aspx DECLARE @tableHTML NVARCHAR(MAX) ; SET @tableHTML = N'<H1>Work Order Report</H1>' + N'<table border="1">' + N'<tr><th>Work Order ID</th><th>Product ID</th>' + N'<th>Name</th><th>Order Qty</th><th>Due Date</th>' + N'<th>Expected Revenue</th></tr>' + CAST ( ( SELECT td = wo.WorkOrderID, '', td = p.ProductID, '', td = p.Name, '', td = wo.OrderQty, '', td = wo.DueDate, '', td = (p

Finding stored procedures having execute permission

◇◆丶佛笑我妖孽 提交于 2019-11-30 19:56:40
I am using SQL Server 2008 R2. I need to list out all the stored procedures that a database user (MYUSER) has execute permission. Also, I need to list out which are the stored procedures that the user does NOT have EXECUTE permission - but can read the script of the stored procedure Is there any SQL statement or helper function for these purpose? REFERENCE: Granting execute permission on all stored procedures in a certain database Use HAS_PERMS_BY_NAME : select name, has_perms_by_name(name, 'OBJECT', 'EXECUTE') as has_execute, has_perms_by_name(name, 'OBJECT', 'VIEW DEFINITION') as has_view

Normalize unicode string in SQL Server?

拜拜、爱过 提交于 2019-11-30 19:50:28
Is there a function in SQL Server to normalize a unicode string? e.g. UPDATE Orders SET Notes = NormalizeString(Notes, 'FormC') Unicode Normalization Forms: C ​omposition ( C ): A + ¨ becomes Ä D ​ecomposition ( D ): Ä becomes A + ¨ Compatible Composition ( KC ): A + ¨ + fi + n becomes Ä + f + i + n Compatible Decomposition ( KD ): Ä + fi + n becomes A + ¨ + f + i + n i cannot find any built-in function, so i assume there is none. Ideally, if there can be only one, then i happen to need Form C today: Unicode normalization form C, canonical composition. Transforms each decomposed grouping,

How to find list of tables having no records in SQL server

十年热恋 提交于 2019-11-30 19:22:52
How to display a list of tables having no record inserted in them and they are existing in the sql server database.Required is only to show tables with no record in them. Try this: SELECT t.NAME AS TableName, p.rows AS RowCounts FROM sys.tables t INNER JOIN sys.partitions p ON t.object_id = p.OBJECT_ID WHERE t.NAME NOT LIKE 'dt%' AND t.is_ms_shipped = 0 AND p.rows = 0 GROUP BY t.Name, p.Rows ORDER BY t.Name The query goes to the sys.tables and other catalog views to find the tables, their indexes and partitions, to find those tables that have a row count of 0. Alteration to add Schema names:

how to get name from another table with matching id in another table?

隐身守侯 提交于 2019-11-30 18:36:31
问题 I am using sql server 2008 r2 with php in my website. I have 2 tables. 1 is for employees. (int) (nvarchar) (nvarchar) id name type 1 john 2 2 peter 1 3 leah 2 4 frank 1 5 tang 3 2 is for work (int) (nvarchar) (nvarchar) workid name employees 1 task1 1,3 2 task2 2,3 3 task3 1,3,4 4 task4 2 I want to make query which give me work description with employee name where type < 3. Means i want to get result like this. workid name employee 1 task1 john, leah 2 task2 peter, leah 3 task3 john,leah

SQL Server 2008 returns “Memory limit of 10240 KB exceeded for buffered query”

穿精又带淫゛_ 提交于 2019-11-30 18:36:19
I'm trying to fill a HTML table with some SQL Server 2008 r2 data, the controller (php_sqlsrv) works fine, the tables are filled very well, but when I try to retrieve a 2000 or more rows (maybe less) it crashes and shows this message: SQL Error: Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -59 [code] => -59 [2] => Memory limit of 10240 KB exceeded for buffered query [message] => Memory limit of 10240 KB exceeded for buffered query )) How can I fix this? Is this a PHP or a sqlsrv problem? Can I fix this from the SQL Server Management Studio? Change the setting in php.ini.

Executing remote procedure with user-defined table type variable parameter

柔情痞子 提交于 2019-11-30 18:24:58
问题 I'm trying to call a remote stored procedure over a linked server. The problem is, one of the required parameters is a user-defined table types. I can't seem to figure out how to declare a local variable as a user-defined table type from a remote server. This is what I'm trying so far, but it doesn't work: DECLARE @tblVar [REMOTESERVER].REMOTEDB.dbo.user_defined_table_type EXEC [REMOTESERVER].REMOTEDB.dbo.procedure_name (@param1 = @tblVar) However the error I'm getting is: The type name

How to set identity column to created table in SQL server

不羁的心 提交于 2019-11-30 18:16:24
I created a table in SQL Server like this: CREATE TABLE [UserName] ( [ID] [int] NOT NULL , [Name] [nvarchar] (50) NOT NULL , [Address] [nvarchar] (200) NULL CONSTRAINT [PK_UserName] PRIMARY KEY CLUSTERED ([ID] ASC) ) ON [PRIMARY] GO If I want to make ID an identity column, what do I need? Do I need to drop and create this table and set ID to [ID] [int] IDENTITY(1,1) NOT NULL . By using drop and create, all of data from UserName table are lost . Is there another way to set IDENTITY COLUMN to created table 's column without losing data? I use SQL Server 2008 R2 :) ALTER TABLE [UserName] DROP

Full text search installed or not

故事扮演 提交于 2019-11-30 17:28:24
I have instaled SQL server 2008 R2 and when I run this SQL in SQL server management studio: SELECT FULLTEXTSERVICEPROPERTY('IsFullTextInstalled') I get 0 But If I run this: SELECT * FROM sys.fulltext_catalogs I get one row. I want to know If fulltext search is installed on my sql server or do I need to reinstall SQL server with advance options. Please suggest. My answer: If FULLTEXTSERVICEPROPERTY says it's not installed, then I would install from the original media. Run through the installer and simply add Full Text Search from the features page. FTS is fully in the SQL Engine in 2008 so if

MERGE Query and deleting records

六眼飞鱼酱① 提交于 2019-11-30 17:14:55
I have a table that looks something like: AccountID, ItemID 1, 100 1, 200 2, 300 I have a proc that accepts a table value parameter which updates the Items associated with an account. We'll pass something like the following: AccountID, ItemID 3, 100 3, 200 The proc looks something like: procedure dbo.MyProc( @Items as dbo.ItemListTVP READONLY ) AS BEGIN MERGE INTO myTable as target USING @Items on (Items.AccountId = target.AccountId) AND (Items.ItemId = target.ItemId) WHEN NOT MATCHED BY TARGET THEN INSERT (AccountId, ItemId) VALUES (Items.AccountId, Items.ItemId) ; END Based on the passed in