sql-server-2012

Permissions error when attaching a database: “Cannot access the specified path”

℡╲_俬逩灬. 提交于 2019-12-04 23:22:45
I am running SQL Server 2012 Enterprise Edition. I have downloaded the AdventureWorks 2012 OLTP data files (both .mdf and .ldf ). I saved them to the AW folder that I created in My Documents where I unzipped the file. I go to SQL Server Management Studio (SSMS) right-click on database, and click attach in the context menu. In the dialog I click find. The UI does not allow me to navigate to folder. I try typing the full path to the file, and then I get the following error: Cannot access the specified path or file on the server. Verify that you have the necessary security privileges and that the

How to retrieve the input parameter values of a stored procedure

不羁的心 提交于 2019-12-04 23:18:06
I want to create a auditing procedure which will be called in the catch block of all the procedure in my Database. I wanted to store the list of all the input parameters and its values in this auditing DB. Please suggest me, how to achieve this in SQL Server I am not aware of programatically retrieving the list of parameters and their values for a stored proc(Possibly would involve n number of system tables and things like that). Without going into that level of complexity AND if altering the current procedures is a possibility, you could do something on the lines of below. ALTER the existing

I need a check constraint on two columns, at least one must be not null

。_饼干妹妹 提交于 2019-12-04 23:13:35
I have a table in SQL Server with two numeric columns. At least one of these numeric fields must be filled. How do I write a check constraint to verify this? This can be done with a check constraint that verifies null value and matches the result with or create table #t (i int , j int , constraint chk_null check (i is not null or j is not null)) The following are the test cases insert into #t values (null, null) --> error insert into #t values (1, null) --> ok insert into #t values (null, 1) --> ok insert into #t values (1, 1) --> ok late answer, but here is a solution for Sql Server for any

SQL Server dbo.sysdiagrams is a user table or system table

Deadly 提交于 2019-12-04 22:36:32
When use Database Diagrams in a simple database, SQL Server create a dbo.sysdiagrams table in the Table\Systam Tables node (in Microsoft management studio\object explorer). But sysdiagrams table marked as user table in SQL Server. you can get user table by below query. SELECT * FROM sys.tables t WHERE OBJECTPROPERTY(t.object_id,'IsUserTable') = 1 I don't know that sysdiagram table is a system table or is a user table. Exists microsoft_database_tools_support with value 1 In the extended property of sysdiagram, that determine this table created automatically. Alain Tésio System tables are used

Can't save database default locations in SQL Server

*爱你&永不变心* 提交于 2019-12-04 22:15:11
I'm trying to change the default directories for data and logs using SQL Server Management Studio. I change the path then click ok but it always reverts back to the old directory in Program Files. Anyone else seen this bug? I'm using SQL Server 2012 Standard. I do see that the correct values are saved in the registry, but they aren't being obeyed by the studio or other connecting applications that would create new databases. According to Microsoft , you must restart the SQL Server service for this to take effect. You can do this easily via the Configuration Manager , or via the services.msc

Calling a SOAP webservice from TSQL stored procedure

☆樱花仙子☆ 提交于 2019-12-04 20:57:16
问题 I am trying to build a stored procedure in TSQL to call a webservice. I've done this before in Oracle, but it seems like it's not so easy in MSSQL. There are of course many reasons not to do this in a stored proc, but since this procedure is only to be used in a daily batch, performance is not too much of a issue. The thing I want to do is as follows: Send a full name to the webservice, the webservice will return a name divided in things like first name, prefix, lastname, etc. The returned

Rollover sum with grouping in SQL Server

十年热恋 提交于 2019-12-04 19:46:51
I need to do Rollover sum with grouping in SQL Server I need to sum of sales within same year for the later quaters. Data is like shown below Year Qtr sales 2011 1 10 2011 2 5 2011 5 30 2012 4 30 2012 5 2 I would need the output like below Year | quater | salestillnowThisYear 2011 1 10 2011 2 15 (which is 10 + 5 from previous quaters within same year) 2011 5 45 ( 10 + 5 + 30 from previous quaters of this year) 2012 4 30 2012 4 32 (30 + 2 which is 30 from previous quater of this year) There are many ways to achieve Rolling Sum . Here are few options. CREATE TABLE #test (years INT, id INT, sal

Convert Datetime to Unix timestamp

蹲街弑〆低调 提交于 2019-12-04 18:58:05
问题 In Microsoft SQL Server 2012 or above, is it possible to convert a datetime value to Unix time stamp in a single select statement? If so, how can it be done? 回答1: As Peter Halasz mentions in T-SQL DateTime to Unix Timestamp: Converting a datetime to unix timestamp is easy, but involves error prone typing the following: @timestamp=DATEDIFF(second,{d '1970-01-01'},@datetime) Where @datetime is the datetime value you want to convert. The {d ‘yyyy-mm-dd’} notation is an ODBC escape sequence. The

Select the top 1 row from each group

点点圈 提交于 2019-12-04 18:42:27
问题 I have a table that lists the versions of software that are installed: id | userid | version | datetime ----+--------+---------+------------------------ 111 | 75 | 10075 | 2013-03-12 13:40:58.770 112 | 75 | 10079 | 2013-03-12 13:41:01.583 113 | 78 | 10065 | 2013-03-12 14:18:24.463 114 | 78 | 10079 | 2013-03-12 14:22:20.437 115 | 78 | 10079 | 2013-03-12 14:24:01.830 116 | 78 | 10080 | 2013-03-12 14:24:06.893 117 | 74 | 10080 | 2013-03-12 15:31:42.797 118 | 75 | 10079 | 2013-03-13 07:03:56.157

Updating Variable with Current Row Value

十年热恋 提交于 2019-12-04 18:04:15
I am trying to perform a complex operation where I pull the sum for an entire column of data and subtract the running subtotal from the sum for each row. I can do the component parts of Sum and Running Subtotal alone. Used this for running subtotal: sum(UsageMetric) over(order by Nested1.IDNumber) as RunningTotal However, I get this error when trying to comine them: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. So I rigged this up, and it returns the 'stand-alone' running subtotal for a