sql-server-2008-r2

Performance of User-Defined Table Types in SQL Server

流过昼夜 提交于 2019-11-30 07:09:25
问题 We have been using User-Defined Table Types to pass a list of integers to our stored procedures. We then use these to join to other tables in our stored proc queries. For example: CREATE PROCEDURE [dbo].[sp_Name] ( @Ids [dbo].[OurTableType] READONLY ) AS SET Nocount ON SELECT * FROM SOMETABLE INNER JOIN @Ids [OurTableType] ON [OurTableType].Id = SOMETABLE.Id We have seen very poor performance from this when using larger datasets. One approach we've used to speed things up, is the dump the

How to control SSIS package flow based on record count returned by a query?

守給你的承諾、 提交于 2019-11-30 06:46:04
问题 I'm trying to first check if there are any new records to process before I execute my package. I have a bit field called "processed" in a SQL Server 2008 R2 table that has a value of 1 if processed and 0 if not. I want to query it thus: select count(processed) from dbo.AR_Sale where processed = 0 If the result is 0 I want to send an e-mail saying the records are not there. If greater than zero, I want to proceed with package execution. I am new to SSIS and can't seem to figure out what tool

How to display the date as mm/dd/yyyy hh:mm Am/PM using sql server 2008 r2?

那年仲夏 提交于 2019-11-30 06:43:12
My sample query is SELECT D30.SPGD30_LAST_TOUCH_Y from CSPGD30_TRACKING D30 My given date format is like "2013-01-01 00:00:00.000" . I need to convert this date format to "mm/dd/yyyy hh:mm AM/PM" . Do you have any idea about that? I think there is no single format to give them both. Try this using Convert ; Sql-Demo declare @mydate datetime = getdate() select convert(varchar(10),@mydate, 101) + right(convert(varchar(32),@mydate,100),8) | COLUMN_0 | ---------------------- | 02/22/2013 9:36AM | KateA The FORMAT() function is available from version 2012 onwards. Once upgraded, you can use select

SQL Server Find What Jobs Are Running a Procedure

百般思念 提交于 2019-11-30 06:22:09
问题 Is there a way to find out what jobs are using a certain stored procedure? 回答1: This will capture instances where the procedure is explicitly referenced in the job step: SELECT j.name FROM msdb.dbo.sysjobs AS j WHERE EXISTS ( SELECT 1 FROM msdb.dbo.sysjobsteps AS s WHERE s.job_id = j.job_id AND s.command LIKE '%procedurename%' ); If it is called by something else that is called from the job, or the command is constructed with dynamic SQL, this might be a little more difficult to track down.

fastest way to export blobs from table into individual files

你离开我真会死。 提交于 2019-11-30 06:20:50
问题 What is the fastest way to export files (blobs) stored in a SQL Server table into a file on the hard drive? I have over 2.5 TB of files (90 kb avg) stored as varbinary and I need to extract each one to a local hard drive as quickly as possible. BCP seems to work but it will take over 45 days with the speed I'm seeing, and I'm worried that my script will fail at some point because Management Studio will run out of memory. 回答1: I tried using a CLR function and it was more than twice as fast as

SQL Server Management Studio Missing after 2008 R2 Install

社会主义新天地 提交于 2019-11-30 06:13:11
Just installed SQL Server 2008 R2 Developer Edition on my XP box. There is no sign of SQL Server Management Studio (SSMS). Aarg. And I can't seem to see that specific option available in Add Features. What do I do? I did notice that my machine already had the setup files for SQL Server 2008 installed. So I uninstalled everything - first R2 then the setup for 2008, and now when I go to reinstall R2, still no option for SSMS in the feature list. Help! You need to go to Control Panel, Add/Remove Features, pick SQL Server 2008 R2, and click Uninstall/Change. It will ask you if you want to Add,

SQL list of all the user defined functions in a database

删除回忆录丶 提交于 2019-11-30 06:05:41
I am looking for a SQL query that outputs the function definitions for all of the user defined functions in a database catalog. I have found as far as SELECT OBJECT_DEFINITION (OBJECT_ID(N'dbo.UserFunctionName')) AS [Object Definition] and SELECT ROUTINE_NAME FROM information_schema.routines WHERE routine_type = 'function' but I can't think of or find a way to feed the ROUTINE_NAME list to the OBJECT_ID. The purpose here is a searchable text of the user defined function definitions in a database for database change analysis, if something like a full SQL procedure or purposed helper program is

LIKE query with Entity Framework [duplicate]

喜欢而已 提交于 2019-11-30 05:39:48
Possible Duplicate: How to do SQL Like % in Linq? Like Operator in Entity Framework? I'm doing a query like this: var matches = from m in db.Customers where m.Name == key select m; But I don't need m.Name to be exactly equal to key. I need m.Name to be like key. I can't find how to recreate the SQL query: WHERE m.Name LIKE key I'm using SQL Server 2008 R2. How to do it? Thanks. MethodMan Would something like this work for you.. ? var matches = from m in db.Customers where m.Name.Contains(key) select m; this should also work I edited my answer Andrew Cooper var matches = from m in db.Customers

Convert NVARCHAR to DATETIME in SQL Server 2008

人盡茶涼 提交于 2019-11-30 05:21:42
问题 In my table LoginDate 2013-08-29 13:55:48 The loginDate column's datatype is nvarchar(150) I want to convert the logindate column into date time format using SQL command Expected result. LoginDate 29-08-2013 13:55:48 回答1: DECLARE @chr nvarchar(50) = (SELECT CONVERT(nvarchar(50), GETDATE(), 103)) SELECT @chr chars, CONVERT(date, @chr, 103) date_again 回答2: SELECT CONVERT(NVARCHAR, LoginDate, 105)+' '+CONVERT(NVARCHAR, LoginDate, 108) AS LoginDate FROM YourTable Output ------------------- 29-08

stored procedure with variable number of parameters

喜你入骨 提交于 2019-11-30 04:51:39
I have stored procedure where I have to pass parameters, But the problem is I am not sure how many parameters is going to come it can be 1, in next run it can be 5. cmd.Parameters.Add(new SqlParameter("@id", id) Can anyone help how can I pass these variable number of parameters in stored procedure? Thanks You could pass it in as a comma-separated list, then use a split function, and join against the results. CREATE FUNCTION dbo.SplitInts ( @List VARCHAR(MAX), @Delimiter CHAR(1) ) RETURNS TABLE AS RETURN ( SELECT Item = CONVERT(INT, Item) FROM ( SELECT Item = x.i.value('(./text())[1]', 'INT')