sql-server-2008-r2

SQL backup version is incompatible with this server

百般思念 提交于 2019-12-23 17:19:51
问题 I get he following message when i try to restore a database backup to the customers SQL Server 2008. System.Data.SqlClient.SqlError: The database was backed up on a server running version 10.50.1600. That version is incompatible with this server, which is running version 10.00.4064. I hade a made a backup of the database and restored in on a server which had version 10.50.1600, then once i finished my dev work i backed it up but now it wont restore on the customers server 10.00.4064. What are

How to find the total tablespace usage in SQL Server 2008?

こ雲淡風輕ζ 提交于 2019-12-23 17:18:07
问题 In SQL-server 2008, How would I find (through an SQL query), the percentage of tablespace usage for a particular instance(or all instances) of a SQL Server(2008 R2)? Also, what is the best way (query) to get the list of all the Named Instances of a SQL Server? 回答1: is this what you need: EXEC sp_spaceused null, false result: database_name database_size unallocated space --------------- ------------------ ------------------ DATABASE_NAME 220.25 MB 69.92 MB reserved data index_size unused -----

SQL convert string(date or text) to date

橙三吉。 提交于 2019-12-23 16:36:34
问题 I have a database which has a column called stringNextDue that contains data like dates (UK format) and text (e.g "overdue", "completed") I am trying to create a view that shows courses that are due within a month from now: WHERE CONVERT(DATETIME, mt.stringNextDue , 103) < DATEADD(MONTH, 1, GETDATE()) This throws an error: Conversion failed when converting date and/or time from character string. Which is probably due to the fact that stringNextDue may contain actual strings of text. I tried

Why is TestID not being converted to INT?

▼魔方 西西 提交于 2019-12-23 16:17:40
问题 Dev's and DBA's, I think I figured out a bug in SQL 2008 R2, unless one of you can explain the below. Can you please explain why TestID is being converted to NUMERIC instead of INT in this scenario? Please be advised that this is just a sample to show you the problem I came across while trying something bigger such as an automation script that will convert data imported from Excel or Notepad that will be nvarchar/float to the appropriate data types, int, numeric, datetime, varchar. CREATE

Distinct count to exclude NULL

久未见 提交于 2019-12-23 16:15:27
问题 Is there a way to create a calculated measure that can do a distinct count, but excluding the null values? For example, if I have: 10, 20, 20, null; the distinct count is 3, but can I have the answer as 2? 回答1: put a where condition to where the measure is not null 回答2: you could try this: with cte ( "counter" ) as ( select 1 as "counter" from "YOURTABLE" group by "COLUMNNAME" having ( "COLUMNNAME" IS NOT NULL ) ) select SUM( "counter" ) from cte @ edit: quite easier variant: SELECT COUNT(

Issue Calculating from Rows and Columns(Summing two columns with the third of a different row)

若如初见. 提交于 2019-12-23 15:51:20
问题 With reference to my previous question Adding columns resulting from GROUP BY clause SELECT AcctId,Date, Sum(CASE WHEN DC = 'C' THEN TrnAmt ELSE 0 END) AS C, Sum(CASE WHEN DC = 'D' THEN TrnAmt ELSE 0 END) AS D FROM Table1 where AcctId = '51' GROUP BY AcctId,Date ORDER BY AcctId,Date I executed the above query and got my desired result.. AcctId Date C D 51 2012-12-04 15000 0 51 2012-12-05 150000 160596 51 2012-12-06 600 0 now I have a another operation to do on the same query i.e. I need the

Using case statements with IsDate in a SQL where clause

依然范特西╮ 提交于 2019-12-23 12:09:39
问题 I am trying to clean up the where clause statement in the following code: SELECT CONVERT(datetime, [UTC_Time_Stamp], 127) AS TimeStamp FROM Table WHERE CASE WHEN ISDATE([UTC_Time_Stamp]) = 1 THEN CONVERT(datetime, [UTC_Time_Stamp], 127) ELSE CAST('1/1/1900' AS datetime) END > CAST('11/09/2012' AS datetime) AND CASE WHEN ISDATE([UTC_Time_Stamp]) = 1 THEN CONVERT(datetime, [UTC_Time_Stamp], 127) ELSE CAST('1/1/3000' AS datetime) END < CAST('11/10/2012' as datetime) ORDER BY TimeStamp; UTC_Time

Query msdb.dbo.sysssispackages XML for specific values

两盒软妹~` 提交于 2019-12-23 11:59:08
问题 I'm trying to query msdb.dbo.sysssispackages for active maintenance plans, and I can't wrap my head around how to query the XML in the packagedata column. I've found some other XML-related SQL questions on SO but so far nothing seems to quite fit what I'm looking for. The XML in msdb.dbo.sysssispackages.packagedata looks like this: <DTS:Executable DTS:ExecutableType="Microsoft.SqlServer.Management.DatabaseMaintenance.DbMaintenanceReindexTask, Microsoft.SqlServer.MaintenancePlanTasks, version

Hyperlink a value in SQL Server query result in SSMS

余生颓废 提交于 2019-12-23 09:41:22
问题 I am trying to create something for our QA people, where a query that they would run will return a column with hyperlinked values. I am using SQL Server 2008 R2 and SSMS. How will I hyperlink results in SSMS so a linked value opens in a browser? The idea is that the Qa person can simply click on the link and the appropriate ASP.Net app would open in a browser window. The query is as below, which is right now showing an unlinked string under DocLink column. SELECT DocNumber, 'https://www.xyz

Run a C# Console Application from SQL Server Agent (Job)?

江枫思渺然 提交于 2019-12-23 08:59:32
问题 This might be a very simple question but I have been trying for last 4-5 hours w/o success. :( I have a C# console application that simply opens an excel file. This excel file has Workbook_Open() event, which runs my macro. My macro simply renames sheet1 to RenameSheet1 in an active worksheet. I could run my C# project from IDE. I want to run this project from SQL job(SQL server 2008). How do I do it? Please help me get this working. Thanks. As per SilverNinnjas' suggestions to create a proxy