sql-server-2008-r2

SQL how to convert row with date range to many rows with each date

China☆狼群 提交于 2019-11-30 04:51:03
问题 If I have a table that looks like this begin date end date data 2013-01-01 2013-01-04 7 2013-01-05 2013-01-06 9 How can I make it be returned like this... date data 2013-01-01 7 2013-01-02 7 2013-01-03 7 2013-01-04 7 2013-01-05 9 2013-01-06 9 One thing I was thinking of doing is to have another table that just has all the dates and then join the table with just dates to the above table using date>=begin date and date<=end date but that seems a little clunky to have to maintain that extra

TSQL query to find un-used stored procedures

丶灬走出姿态 提交于 2019-11-30 04:49:45
I am trying to track down all stored procedures in a database that have never been used, or that have not been used in many months. I would like to find a query to show all the stored procedures that are not in use so that those stored procedures can be analyzed to determine if they can be removed. I am familiar with sys.procedures, but don't know how to determine if a procedure is in use or not. SELECT * FROM sys.procedures; Using SQL Server 2008 R2. UPDATE UPDATE UPDATE Using the query from Aaron Bertrand below, slightly modified, this is what I ended up using, and it was perfect. SELECT p.*

Normalize unicode string in SQL Server?

廉价感情. 提交于 2019-11-30 04:26:46
问题 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

Finding stored procedures having execute permission

两盒软妹~` 提交于 2019-11-30 03:54:49
问题 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 回答1: Use HAS_PERMS_BY_NAME: select name, has_perms_by_name

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

本小妞迷上赌 提交于 2019-11-30 03:33:45
问题 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. 回答1: 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,

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

女生的网名这么多〃 提交于 2019-11-30 02:37:58
问题 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

How to join two unrelated tables in sql

落爺英雄遲暮 提交于 2019-11-30 00:44:59
问题 I have two tables: Table 1: Formulas FormulaId Formula Text 1 [Qty] * [Rect] 2 [Qty] * [Al] 3 [Mt] * [Cat] Table 2: Context ContextId Name 1 Test 1 2 Test 2 3 Test 3 4 Test 4 I need to join those somehow in sql server 2008 R2 to get a table where for each context id I will have a full list of formulas, i.e. Result ContextId Name FormulaId Formula Text 1 Test 1 1 [Qty] * [Rect] 1 Test 1 2 [Qty] * [Al] 1 Test 1 3 [Mt] * [Cat] 2 Test 2 1 [Qty] * [Rect] 2 Test 2 2 [Qty] * [Al] 2 Test 2 3 [Mt] *

Find the last time table was updated

爷,独闯天下 提交于 2019-11-30 00:07:45
I want to retrieve the last time table was updated(insert,delete,update). I tried this query. SELECT last_user_update FROM sys.dm_db_index_usage_stats WHERE object_id=object_id('T') but the data there is not persisted across service restarts. I want to preserve the stats even if the service restarts. How can I achieve it? If you're talking about last time the table was updated in terms of its structured has changed (new column added, column changed etc.) - use this query: SELECT name, [modify_date] FROM sys.tables If you're talking about DML operations (insert, update, delete), then you either

How to count total number of stored procedure and tables in SQL Server 2008

冷暖自知 提交于 2019-11-30 00:05:15
I have database Test1 in SQL Server 2008 R2. On the live server I took backup from there and restore it at our local machine as Test2 and added some tables and procedures. If we restore Test2 back onto the live server so is it any query which can get tables name and procedure name which is only in test 2 not in test 1 or SQL Server treated it as totally different database? And what is the query if I want to know only the number of difference of Test1 and Test2 databases This will give you the count of tables and stored procedures. SELECT CASE TYPE WHEN 'U' THEN 'User Defined Tables' WHEN 'S'

Attaching an MDF file without LDF file

霸气de小男生 提交于 2019-11-29 23:27:38
问题 Does anyone know if there is a way to attach just a SQL Server MDF file (without .LDF) file. The log file for database got deleted and I have tried to attach the MDF, it does not work. I have tried running the script to attach file but did not help: USE master; GO EXEC sp_attach_single_file_db @dbname = 'AdventureWorks2012', @physname = N'C:\ProgramData\Homefront\Database\DB1.mdf'; Please helpp !!!! 回答1: Also try these methods... CREATE DATABASE AdventureWorks2012 ON (FILENAME = N'C: