sql-server-2008-r2

To get the Id's between two dates

醉酒当歌 提交于 2019-12-24 11:50:29
问题 I have a table WEEK_ID WEEK_STARTDATE WEEK_YEAR WEEK_MONTH WEEK_CREATEDTS 252 10/26/2008 2008 11 2008-10-07 15:10:00.000 253 11/02/2008 2008 11 2008-10-07 15:10:00.000 254 11/09/2008 2008 11 2008-10-07 15:10:00.000 255 11/16/2008 2008 11 2008-10-07 15:10:00.000 256 11/23/2008 2008 12 2008-10-07 15:10:00.000 257 11/30/2008 2008 12 2008-10-07 15:10:00.000 258 12/07/2008 2008 12 2008-10-07 15:10:00.000 259 12/14/2008 2008 12 2008-10-07 15:10:00.000 260 12/21/2008 2008 12 2008-10-07 15:10:00.000

SQL_ATTR_QUERY_TIMEOUT Not Timing Out

我们两清 提交于 2019-12-24 11:39:10
问题 Setup Using SQL Server 2008 R2. I have an ODBC call to a stored procedure that should time out after 3 seconds by using the SQLSetStmtAttr function with the SQL_ATTR_QUERY_TIMEOUT parameter. SQLSetStmtAttr( command, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)&timeOut, NULL ); Test I set a delay in the stored procedure for 15 seconds. The stored proc does indeed take just over 15 seconds to return. WAITFOR DELAY '00:00:15' Issue The problem is that the stored procedure returns correctly, where I am

SQL MAX date without group by

社会主义新天地 提交于 2019-12-24 09:49:05
问题 I have the following table Location Type Date A TestType 10-10-2013 A TestType 05-05-2013 A BestType 06-06-2013 B TestType 09-09-2013 B TestType 01-01-2013 I want to return the max date for each location regardless of the type but I must return all 3 columns. Desired result: Location Type Date A TestType 10-10-2013 B TestType 09-09-2013 What would be the best way to do this? I've looked into using RANK() Over Partition , but can't get it to work properly. 回答1: Using row_number() function and

How to define a new column in a stored procedure query

匆匆过客 提交于 2019-12-24 09:30:14
问题 I have a stored procedure which realizes a pivot table. My Select statement was defined in a variable @query . Here is the code: BEGIN SET NOCOUNT ON; DECLARE @colNo nvarchar(max) DECLARE @query nvarchar(max) SET NOCOUNT ON; WITH vals AS ( SELECT DISTINCT t.No FROM QR_Tests t ) SELECT @colNo = COALESCE(@colNo + ', ', '') + '['+ No +']' FROM vals ORDER BY No SET @query = 'SELECT * FROM ( SELECT CASE WHEN GROUPING(No) = 0 THEN CAST(No as CHAR(12)) ELSE [ALL] END As No, CASE WHEN GROUPING(quote)

SSIS: database xyz cannot be opened. It is in the middle of a restore

蓝咒 提交于 2019-12-24 07:59:02
问题 In SSIS 2008, is there is way to design an SSIS package around the problem when an OLE DB data source returns an error like this "Database [xyz] cannot be opened. It is in the middle of restore."? I am hoping there is a way to design a loop into an SSIS 2008 package to trap this error, maybe wait 5 or 10 minutes for the source DB to finish restoring (from log shipping for example) and then try again - with a max retry limit built in. Thank You. 回答1: Yes. When you connect, don't connect to

SQL Server 2008 R2 on Server 2012 R2 web site connection issue

泄露秘密 提交于 2019-12-24 07:45:42
问题 I have been using this connection string with no problem on a number of databases and MS operating systems. Windows Server 2003, 2008 R2 and 2012 R2 Eval, all Express versions. I am now trying to deploy to a new Windows Server 2012 R2 installation and I am getting some errors. I have the SQL Server 2008 R2 installation on the Windows Server 2012 R2 machine. My con string: connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\myDB.mdf;Integrated Security=True;User

How to append data from an Access table to a SQL server table via a pass-through query?

旧街凉风 提交于 2019-12-24 07:45:41
问题 It seems like it's only possible to use a pass-through query to retrieve data from your SQL Server tables and into MS Access. But how about the other way? From an Access table to a SQL server table. What are my options from within MS Access when I need high performance? (The normal approach of having an append query that appends to a linked table is simply too slow ) In an pass-through query I cannot reference MS Access tables or queries, and therefore my INSERT INTO statement cannot work. Is

Concatenate nvarchar and int while maintaining Distinct result

邮差的信 提交于 2019-12-24 07:17:00
问题 I'm trying to count all the items for each brand and concatenate the brand name + number of items. I have this query in SQL Server 2008 R2: SELECT DISTINCT Brands.BrandName + ' ' + COUNT(Items.ITEMNO) as ITEMSNO, Brands.BrandId FROM Items, Brand_Products, Brands WHERE Items.ITEMNO=Brand_Products.ItemNo AND Brands.BrandId=Brand_Products.BrandId AND Items.SubcategoryID='SCat-020' GROUP BY Brands.BrandId, Brands.BrandName, Items.ITEMNO I'm trying to concatenate 2 fields, but I have 2 problems:

What causes DMV to show a NULL query plan?

会有一股神秘感。 提交于 2019-12-24 07:13:49
问题 When I execute this simple SP and then check for the query plan from the DMV query that follows, the query plan comes back as NULL. But if I comment out the else block in the SP (or change it to not reference temp table), the DMV query does show a query plan. Any idea what is causing this difference? And does a NULL query plan mean that nothing was cached? I'm using SQL Server 2008 R2. CREATE PROCEDURE dbo.SampleSp ( @Option TINYINT ) AS DECLARE @RowCount INT; -- Get ID into local temp table

EXECUTE @Var character limit SQL Server 2008 R2

寵の児 提交于 2019-12-24 05:54:51
问题 I've been looking all over for an answer to this, but nothing is explicit so hopefully someone knows off the top of their head. When using EXECUTE with a VARCHAR(MAX) variable, is there a character limit? I've done some experimenting and it seems that when load a variable and then call EXECUTE @var , there is a character limit on what is actually passed through to the server. When calling EXECUTE without the variable and just building the string there, everything appears to work.... is there