sql-server-2005

Fnd consecutive dates withing a defined span where a Trainer is available to schedule

隐身守侯 提交于 2019-12-23 22:03:31
问题 We have a table used for assigning trainers to planned customer installations. In the table, there is a record for each trainer, for each day of the year. (We can, and sometimes do, work weekends.) I am building a search tool that allows our schedulers to search for a trainer that is available X number of days between dates Y and Z. Table mySchedule Trainer Date Dirty (Bit) ------------------------------------------------ Joe 06/01/2013 0 Jessica 06/01/2013 0 Alan 06/01/2013 0 Heather 06/01

Sql Trigger - which table does it belong to?

只愿长相守 提交于 2019-12-23 21:44:09
问题 Is there a way within a Sql Server 2005 Trigger to get the name and schema of the table that the trigger is attached to during execution? 回答1: SELECT OBJECT_NAME(parent_id) AS [Table], OBJECT_NAME(object_id) AS TriggerName FROM sys.triggers WHERE object_id = @@PROCID Then you can also use OBJECTPROPERTY to get extra info, such as after/before, delete/insert/update, first/last etc 回答2: This is a dirty way to know it SELECT o.name FROM sysobjects t JOIN sysobjects o ON t.parent_obj = o.id WHERE

Dynamic Pivot Query without storing query as String

筅森魡賤 提交于 2019-12-23 21:32:09
问题 I am fully familiar with the following method in the link for performing a dynamic pivot query. Is there an alternative method to perform a dynamic pivot without storing the Query as a String and inserting a column string inside it? http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx 回答1: Short answer: no. Long answer: Well, that's still no . But I will try to explain why. As of today, when you run the query, the DB engine demands to be aware of the result set

Can I treat the results of a stored procedure like a table?

Deadly 提交于 2019-12-23 20:07:43
问题 Is it possible to do something like this in sql server 2005? WITH tmpTable AS (EXEC spWhatever) Or any other way I can query the data returned from the sp? Thanks!!! 回答1: Temp table: CREATE TABLE #foo (col1 int, col2 char(10), ...) INSERT #foo EXEC myproc Or loopback (not sure if this still works). Edit: Could be OPENROWSET as per SQLMenace's answer SELECT * FROM OPENQUERY (MyServername, 'USE MyDB EXEC myproc') 回答2: only with a loopback query if you don't first want to create the table, see

Moving SQL2005 app to SQL2008

元气小坏坏 提交于 2019-12-23 19:19:59
问题 I will be moving our production SQL2005 application to SQL2008 soon. Any things to lookout for before/after the move? Any warnings, advices? Thank you! 回答1: Change your compatibility level on the database after moving it to the 2008 server. By default, it will still stay at the old compatibility level. This will let you use the new goodies in SQL 2008 for that database. If you're using the Enterprise Edition of SQL 2008 and you're not running at 80-90% CPU on the box, turn on data compression

keeping one connection to DB or opening closing per need

非 Y 不嫁゛ 提交于 2019-12-23 19:04:05
问题 I looking for a best practice in following case, with reasons why each way is better. I have one DB with about 10~20 client applications that connecting to one main DB server. There can be about 200 calls from one client to the DB per minute, in really rare cases. The application are multithreaded, about 20 threads per application. What will be best practice here to keep only one connection to the DB per application and reuse it per application . OR opening new connections per needed call and

# ifdef type conditional compilation in T-SQL sql server 2008 2005

柔情痞子 提交于 2019-12-23 18:52:53
问题 For sake of backwards compatibility I need to have a stored proc run on both sql server 2005 AND sql server 2008. However due to some commands being deprecated in sql server 2008 my script compiles on 2005 but fails on 2008. I am looking for the c++, c# equivalent of #define, #ifdef so I can compile the same script on 2005 & 2008. What is the standard practice on this ? Attached screenshot explains in detail. thank you 回答1: Use dynamic SQL: if (@returnVal = 1) exec ('backup log myDB with

Using SQL Credential to Open a file with OpenRowSet

你。 提交于 2019-12-23 18:50:41
问题 I am attempting to run the below statement: INSERT INTO table SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0; Database=//server/folder/file.xls; HDR=YES;', 'SELECT * FROM [Sheet1$]') However, I am receiving the below error: OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "The Microsoft Access database engine cannot open or write to the file '\\server\folder\file.xls'. It is already opened exclusively by another user, or you need

SQL Server 2008 T-SQL features do not respect compatibility levels

拜拜、爱过 提交于 2019-12-23 18:10:09
问题 I have inadvertently used a couple of the SQL Server 2008 T-SQL features in a script containing a function which will be deployed to numerous customer databases, some of which will be SQL 2005. An example of an offending statement: create function dbo.fnThisWontWorkOnSQL2005 () returns varchar(max) as begin declare @intCounter int = 2 return @intCounter end select dbo.fnThisWontWorkOnSQL2005() On a SQL2008 instance this will return 2. On a SQL2005 instance this advises "Cannot assign a

How do I create parametrized XPath queries in SQL server?

非 Y 不嫁゛ 提交于 2019-12-23 17:57:51
问题 I am trying to write a parametrized query in SQL server that uses a parameter value as part of the XPath, however it does not seem to work the way I would expect it to. Here is my sample: create table ##example (xmltest xml) declare @LanguagePath varchar(75) set @LanguagePath = '(/languages/language[@id="en-US"])[1]' insert into ##example values ('<languages> <language id="en-US">c</language> <language id="es-ES">c</language> </languages>') insert into ##example values ('<languages> <language