You can send the single request to SQL server instead N requests, where N is the number of your tables, using the UNION clause. You need some like this request: SELECT SUM(C) FROM ( SELECT COUNT(*) AS C FROM {Table1} WHERE IMEI = @IMEI UNION SELECT COUNT(*) AS C FROM...

I guess the MSDN has mentioned at the top itself that this applies to the 2008 and higher versions. So it would be 5000 for 2014 version as well. Applies to: SQL Server 2008 R2 and higher versions. From the MSDN When the Database Engine checks for possible escalations at...

I have an answer for that one actually. You will need to set your connection string as an expression and either hard code or parametrize your user and password. The password is encrypted based on information from the machine that it is encrypted on. Once you move that encrypted property...

Adding an additional answer because really there were two issues. The real root seems to be with the stored procedure. I don't know why it wasn't consistently causing problems, but I rebuilt it using dynamic SQL to only include WHERE filters for parameters that are present. Originally, I had something...

You can do it using pivot, with something like this: SELECT OccuredDate, [1], [2], [3], [4] FROM ( SELECT OccuredDate, TypeID FROM Table1) AS SourceTable PIVOT ( count(TypeID) FOR TypeID IN ([1], [2], [3], [4]) ) AS PivotTable And per month version: SELECT DATEADD(month, DATEDIFF(month, 0, OccuredDate), 0) as Month,...

If the user you are deploying with is not a member of the Analysis Serices administrators group, you can modify role membership using the following procedure. Run SQL Server Management Studio as administrator Open the Analysis Services server in the Object Explorer Go to Properties Go to Security Add the...

The error means that one of your subqueries (the select rate from dbo.rates where region =) is returning multiple values. You have two (or more) records for at least one of your region names on that table. You could (should) be doing this update with a JOIN instead of a...

Add a new item to your project of type Schema (listed under SQL Server > Security). For the objects that belong to this schema, add them as you normally would to your project. They will default to the dbo schema so you will have to change that in each object's...

You may find the handling of defaults a bit counter-intuitive in SQL Server. The syntax is: DEFAULT constant_expression It so happens that SQL Server extends the definition of constant_expression to include non-deterministic scalar functions, such as getdate(). These are functions that return a different value each time they are called,...

Backup and restoring a database will leave any indexes in the same state as they were prior to your move. Rebuilding them will only help if they are a) fragmented and b) truly the cause of the slowdown you are seeing, but its more likely that your new hardware or...

The "non-clustered" indexes you're referring to are actually Range indexes. Both Hash and Range indexes are non-clustered, and there are no "clustered" indexes in in-memory OLTP tables (the primary key is forcibly implemented as a clustered hash index). Range indexes are implemented via modified B-trees and you can read more...

How can i use the longitute and latitute to store location within a geography column?(because it's supposed to be only one geographic point not two right? not one for longitute and one for latitute?) You can use geography::STPointFromText / geography::Point to store longitude and latitude in a geography datatype....

In general, joining varchar and nvarchar columns 'just works', with the following important caveats that generally boil down to "...but you shouldn't do it if you can avoid it": 1) Mismatching varchar/nvarchar in queries and joins can cause huge performance issues. Because the database has to basically perform a function...

It is obvious that '' means blank (Not null) and it exists between two consecutive letters also. (As it is blank) So Sql can not go on replacing that blank in between every letter with the string you want. That's why you can not replace '' Check this query SELECT...

This can be solved using the aggregate function sum() with an over () clause. In the query I only partitioned the data based on week, but maybe you want to include the item_no as part of the partitioning too if there are multiple products. I think this query should give...

As per comments, First you need to install an instance of SQL Server if you don't already have one - https://msdn.microsoft.com/en-us/library/ms143219.aspx Once this is installed you must connect to this instance (server) and then you can create a database here - https://msdn.microsoft.com/en-US/library/ms186312.aspx...

If you consider this table and these test values: DECLARE @tbl TABLE(model INT,speed INT,ram INT,hd FLOAT,cd VARCHAR(10),price FLOAT) INSERT INTO @tbl VALUES (1233,800,128,20.0,'50x',970.0000) You could do something like this: SELECT unpvt.chr, unpvt.value FROM ( SELECT CAST(model AS VARCHAR(10)) AS model, CAST(speed AS VARCHAR(10)) AS speed, CAST(ram AS VARCHAR(10)) AS ram,...

SQL Server 2012 onwards, you can use TRY_PARSE: -- If the culture argument isn't provided, the language of current session is used. SELECT TRY_PARSE('Thu, 4 Jul 2013 09:18:24' AS datetime2) AS 'datetime2'; TRY_PARSE: Returns the result of the expression, translated to the requested data type, or null if the cast...

I believe that the exact opposite is the case. The transaction record is a logical transaction that describes the transaction rather than all of the modifications to the indexes that go along with a non In-Memory table. The log contains the logical effects of committed transactions sufficient to redo the...

There is a work around, but you're not going to like it. You need to create a wrapper procedure, that will define the meta data and execute the orginal procedure based on what columns are supplied to the wrapper. Here is a Link to a MSDN blog where they discuss...

As it turns out the issue was environmentally related and pretty straight forward: First of all, I was attempting to back up from a non-shrunk back up version of the origin database. The size of the log files was actually a known issue, hence we usually back up from a...

If you just want the order number, you can use MAX again since you know the post date will also be the MAX due to your subselect: SELECT MAX(OrderNo), MAX(PostDate) FROM table WHERE PostDate = (SELECT MAX(PostDate) FROM table) ...

The value "cnInvestTracker" itself isn't a valid connection string. Which is what you're trying to use here: new SqlConnection("cnInvestTracker") That constructor doesn't want the name of a connection string, it wants the connection string itself: new SqlConnection(ConfigurationManager.ConnectionStrings["cnInvestTracker"].ConnectionString) (You may have to add a reference to System.Configuration, and you may want...

I am simply wondering if this is even possible in SQL Server 2014 Yes, you can create table-valued user defined functions that return, well, a table value. So the string 'ABC' would be returned as: COL1 COL2 COL3 A B C Well, now you're in trouble - table-valued functions...

Use the original query as a derived table, then MAX the columns: select MAX('2010'), ... from ( SELECT case when Year(LOAN_START_DATE) = 2010 then max(LOAN_RES_BANK_CODE) else 0 end as '2010', ... ) ...

This should not be an issue. By default a database project creates constraints with the NoCheck option - meaning SQL Server will not validate the data. Then, after postDeploy it will check the constraint. Take a look at you deployment script and it will validate this.

Martin is right - use MERGE for this. You could do it all in one statement if you didn't have two row entries to INSERT - as such you could dump to a temp table and do the following: CREATE TABLE #answers (UserTestID INT, QuestionID1 INT, AnswerID1 INT, QuestionID2 INT,...

If I understand what you want is the average of the sales made on the same date for the last five years for each product. If so I think this might be what you want: select s.day, oa.* from sales s outer apply ( select avg(product1*1.0) p1, avg(product2*1.0) p2, avg(product3*1.0)...

I don't understand why you have so many different columns. You should have one row per stock per time unit. I would envision a structure with a few dozen columns: Stock Identifier Date (or date/time) 30 or so measures per stock You seem to want to store things in columns...

You don't need to use recursion for this if you are using a modern version of SQL Server that can do aggregation as window functions. Then you can do sum() as a window function: update t1 set total = y.total from (select *, rn = ROW_NUMBER() over (order by id)...

you can use this query SELECT total_elapsed_time FROM sys.dm_exec_query_stats WHERE sql_handle in (SELECT most_recent_sql_handle FROM sys.dm_exec_connections CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handle) WHERE session_id = (@@spid)) ...

Yes, there is a simple solution. It's called transaction management: SET XACT_ABORT ON BEGIN TRANSACTION -- Do your things COMMIT TRANSACTION If anything fails, the whole transaction will be rolled back, as if it never existed....

Like SQLCMD, BCP is a stand-alone command-prompt utility that must be invoked from a command prompt. If the source text and format files reside on your client, you'll need to add the -S -U and -P parameters like you do with SQLCMD. For example: bcp databasename.schemaname.transitschedule in calendar_dates.txt -f calenar_dates.fmt...

For anyone who runs into something similar, what I ended up doing is programmatically writing a simple batch file to kick off the installer, creating a 'run once and delete' task, and then waiting for it to finish. I had admin privileges, so I just had the task run under...

Yes. All SQL Server releases, from 2005 to 2014 inclusive, are compatible with each other at the Service Broker layer. In fact the 2008 instances are not even going to be able to figure out they are talking to 2014. You should be able to migrate one machine at a...

There are two parts to your question. The features of SQL Server Developer Edition are identical to the features in Enterprise. The only difference is Developer edition is not license for production use. In addition, the SQL Server Developer software isn't technically licensed, each developer that uses the software must...

I think it is a or condition you need: SELECT a.Account_ID FROM Accounts a WHERE ((@FirstName='' and a.FirstName is null) or a.FirstName = @FirstName) /*Add check if @FirstName = '' then a.FirstName IS NULL */ AND a.LastName = @LastName AND a.Middle = @MiddleName AND a.Email = @Email AND a.Company =...

One approach you can take is the following, which uses a CASE statement to allow you to differentiate between numeric and non-numeric values of Column1: -- Some temporary tables to make the example work CREATE TABLE #SRC (Column1 VARCHAR(50)) INSERT INTO #SRC (Column1) VALUES ('First'), ('Second'), ('45'), ('Fourth') CREATE TABLE...

Try this: SELECT TOP 2 UnitNumber, Patient, VisitID, AdmitDate, DischargeDate, PrevDisDate, DaysBtwnVisits FROM #tblTempCalculations AS T1 WHERE T1.ReadmittedFilter = 1 AND T1.UnitNumber IN (SELECT UnitNumber FROM #tblTempCalculations AS T2 WHERE DischargeDate BETWEEN @FromDischargeDate AND @ThroughDischargeDate) ORDER BY DischargeDate DESC ...

For testing purposes only does authentication pass for user BI_USER if the users SERVER ROLE is edited to give it the sysadmin privilege. If the answer is yes remove the sysadmin privilege and attempt to isolate which privilege is required to authenticate. What OS is SQL 2014 hosted on out...

I asked a similar question over on the Microsoft forum and was told that DBCC DBREINDEX is not supported on 2014. I find this odd, since it works... sometimes. But, I can't discount language barrier. And, each time I have tried a similar statement: ALTER INDEX ALL ON QST2D REBUILD;...

Found the solution to this problem so I figured I'd answer it here in case anyone else runs into this problem. the list of supported formats for URL access listed on Microsoft's website here shows the following list: HTML4.0, MHTML, IMAGE, EXCEL, WORD, CSV, PDF, XML, and NULL It does...

If you only want to allow 5 image files, there is no need to bother making thumbnails before testing the number of files. Since FileDialog.FileNames Property returns an array of strings, the first thing you want to do after testing that the DialogResult is Ok, is test the length of...

This link should give you everything you need about setting up your firewall to work with SSIS and its service. The port it uses seems to be port 135 Configure a Windows Firewall for Access to the SSIS Service...

As per my understanding of your query, I have been shared my suggestion below : 1.My point of view ,you can get your expected output by using stored procedure in Database. 2.Because Hopefully You stored the values of employee information, leave type ,leave details are into separate table with the...

There are Two types of Triggers, Instead Of Triggers that fires Instead of the Triggering action After or For Triggers that fires after the Triggering action. Catalog View sys.triggers's column is_instead_of_trigger will tell you whether is an Instead of trigger or not, if value 0 then it is For or...

Your trigger in Oracle is FOR EACH ROW. This type of triggers is not directly supported by SQL Server. So SSMA applies a template replacement for them using INSTEAD OF trigger and loop over inserted. Can you enable ROWID at least for tables with triggers (option "Add ROWID column for...

SELECT * FROM sys.dm_db_persisted_sku_features; This will show you what features you have enabled that need to be disabled. I would restore a backup to an enterprise instance, and then begin to work from there to disable enterprise features After the above query returns no results you should be fine....

The answer is to make sure you have an empty stop list associated with the index. It isn't enough to simply have no stop list. CREATE FULLTEXT STOPLIST [EmptyStopList] ; GO ALTER FULLTEXT INDEX ON MyTable SET STOPLIST [EmptyStopList] ...

You don't need the GROUP BY. You do need a WHERE condition in the subquery to correlate the Acct value from the row of the outer query with the subset of values you want to concatenate in the inner query. You will need to add the DISTINCT after the...

Does PRINT len(@string) show the correct length? If so the PRINT @string is the problem. The print does only output up to 4000 chars. Try SELECT @string in order to output the result as a row which is not truncated....

So as it turns out, the client is joining from a different lan so the failover partner registered on the sql server is not resolvable on the client. SELECT DB_NAME(database_id) AS 'DatabaseName', mirroring_partner_instance FROM sys.database_mirroring WHERE mirroring_guid IS NOT NULL; Will give you the "name" of the failover partner when...

The answer to your questions a, b and c (if you're using SSIS transformation components in SSIS) is essentially “yes, all new data and existing data required for transformation will flow into SSIS instance, and the resulting merged data will flow out of SSIS instance to the target server”. More...

Simply, because you are Grouping by d.categoryid - And there is no grouping by this column, which would return 0 for sum(datavalue): http://sqlfiddle.com/#!6/5e44cb/4 (it's 89) If you could add your expected output to your post, we might be able to help you with the query you need....

Usually, it is considered a good practice to free up resource as long as you don't need it anymore. So I'd add DROP TABLE at the end of stored procedure. Temporary table lives as long as connection lives. Usually, applications use connection pooling (it is configurable) and connection doesn't close...

There is no other solution than re-factoring your code if you wish to upgrade to SQL2014. The example below demonstrates that setting the compatibility level to 2008 does not resolve this error. You will have to modify all your stored procedures and views. ALTER DATABASE database_name SET COMPATIBILITY_LEVEL = 100...

It means that it is not a table, but either a View, or a Table-Valued Function, or one of several other types of objects. Use this instead: SELECT * FROM sys.objects WHERE [object_id] = 584895884; Please note that the [object_id] field is a number, not a string, so shouldn't be...

not really - many injections involve comments (to comment out the rest of the regulare statment) so you could check for comments (-- and /*) and the ; sign (end of statment). On the other side if you allow your users to put anything into the filters - why should...

You can run update with join to get row_number() within [type] group for each row and then concatenate this values with [type] using [index] as glue column: update t1 set t1.[type] = t1.[type] + ' ' + cast(t2.[rn] as varchar(3)) from [tbl] t1 join ( select [index] , row_number() over...

OK, with your help, and a help from a friend, i solved the problem like this. Select ROW_NUMBER() OVER (PARTITION BY Field1 ORDER BY Field1) AS order_num, Field1, Value into #tab1 from Source_Table Order by Field1 Select * from #tab1 PIVOT (Max(Value) FOR order_num IN ([1], [2], [3], [4], [5]))...

In your example 33883.50 * -1 / 1.05 is evaluated as 33883.50 * (-1 / 1.05) instead of (33883.50 * -1) / 1.05 which results in a loss in precision. I played a bit with it. I used SQL Sentry Plan Explorer to see the details of how SQL Server...

Here are the details on licensing: http://azure.microsoft.com/en-us/pricing/licensing-faq/ Inbound data is not charged, but egress is charged. Pricing for egress is located here: http://azure.microsoft.com/en-us/pricing/details/data-transfers/...

Expanding on what Deigo Garbar has already suggested. If you want to use the expression as the default value in your table you would need to put this expression in a function. But the problem is a UDF function will not allow you to use NEWID() function in it, it...

You need to determine the format of the value you are converting before you can convert it. If it's simply between those two formats, you can simply search for - to determine it's format. I would also suggest storing the value in a datetime column as opposed to a varchar,...