Click here to Skip to main content
15,893,487 members
Everything / Database Development / SQL Server / SQL Server 2012

SQL Server 2012

SQL-Server-2012

Great Reads

by AshishShukla6
This tip describes step by step implementation of executing stored procedure having user-defined table type as a parameter in entity framework using EntityFrameworkExtras package.
by Sarathi Balakrishnan
Reset SQL server SA (System Admin) Password when you have lost all possible ways to connect to SQL server and your server has only Windows authentication disabled. You should have Windows administrator permission to do this.
by AhsanAhmed
A brief introduction on how to use FOR XML clause in AUTO mode in Microsoft SQL Server to return data in XML format
by DiponRoy
How to do string split and join in SQL Server

Latest Articles

by DiponRoy
A utility query to find table generations in SQL Server relational database
by DiponRoy
How to do string split and join in SQL Server
by Micah Nikkel
SQL script that dynamically generates the DR scripts for failing over/back all Log Shipped databases. While it makes even a single database failover/failback a more streamlined process, it's most helpful for servers with multiple databases, such as SharePoint, consolidated SQL Servers, etc.
by Luca Astolfi
User defined procedure for make an HTML table from T-SQL Select statment

All Articles

Sort by Updated

SQL Server 2012 

18 Mar 2018 by #realJSOP
Try this: DECLARE @n INT = 2; ;WITH cte AS ( -- create a common table expression with ten rows with the "Value" column -- being set to the row number SELECT TOP(10) Value = ROW_NUMBER() OVER (ORDER BY[object_id]) FROM SYS.ALL_OBJECTS ) -- and then select the rows, identify...
23 Oct 2018 by #realJSOP
This isn't a practical approach because there's a possibility that every record will have a different combination of null column values. When you do a query, *ALL* rows will have the same columns (that you specify in the SELECT statement).
22 Sep 2019 by #realJSOP
The app isn't necessarily running slow, but the queries might be. Honestly, there's nothing we can do for you without seeing the schema, and all the code. Some advice I can give is (in no particular order): 0) Avoid calling user-defined functions from a query. That is a TRUE performance...
29 May 2020 by #realJSOP
Dude, learn how to format your code so we can read it. Beyond that, here is your code formatted. Note the comments: SELECT Q.DTNUMEXE ,Q.DTMOIEXE ,Q.DTANNQIT ,Q.DTMOIQIT ,Q.DTCODBRC ,Q.DTSERQIT ...
5 Nov 2014 by .net333
Hi friends, I need to display a tree node in UI page.. for that need to write a query to retrieve the data in SQL server.. i tried in many ways but not solved.we are passing userid and selecting the data..we need to pass selected user id and we need to get the data in a single...
21 Apr 2015 by .net333
Hi All, I have lot of stored procedures with if conditions..Can any one of you explain how can i create a view and index for below query..if it works for below query I'll implement in all my slowly running stored proceduresCREATE proc...
17 Nov 2014 by /\jmot
See this link..This may help your problem..http://stackoverflow.com/questions/19048705/how-to-find-replace-space-from-hyperlink-src-attribute-sql-server[^]
21 Nov 2014 by /\jmot
Links..http://techbrij.com/html5-geo-location-sql-server-asp-net[^]http://msdn.microsoft.com/en-us/library/bb895266(v=sql.105).aspx[^]
26 Nov 2014 by /\jmot
try like this..select cast(SUBSTRING('11122014',1,2)+'/'+SUBSTRING('11122014',3,2)+'/'+SUBSTRING('11122014',5,4) as date)Updated:declare @val as varchar(max)set @val='11122014101012'select cast((SUBSTRING(@val,1,2)+'/'+SUBSTRING(@val,3,2)+'/'+SUBSTRING(@val,5,4)+'...
1 Dec 2014 by /\jmot
DATALENGTH :Returns the number of bytes used to represent any expression.LEN :Returns the number of characters of the specified string expression, excluding trailing blanks.see this, you'll get the...
5 Dec 2014 by /\jmot
sere here..https://www.simple-talk.com/sql/learn-sql-server/an-introduction-to-sql-server-filestream/[^]http://stackoverflow.com/questions/13674301/sql-server-2008-filestream-file-size-contribution[^]
14 Dec 2014 by /\jmot
try..SELECT *,CAST((Datediff(MINUTE,login_time,logout_time)/60) as decimal(18,2)) AS [TotalHrs_Worked] FROM table_DTR WHERE CONVERT(VARCHAR(10),log_date, 101) BETWEEN '09/01/2014' AND '11/30/2014'
16 Aug 2015 by 1Future
Hello All,Is there a faster to look for a specific table on sql server management studio?I am looking for a certain table , i know the table name but only issue is that there are a 100 of databases and with at least 100 tables in those databases.So there a query to do this at all...
12 Dec 2012 by __TR__
You can include your delete statements in a transaction so that if anything goes wrong with any of the grouped statements, all changes will be aborted.Here is how you will do it.BEGIN TRY BEGIN TRANSACTION DECLARE @Id INT SET @Id = 1 DELETE FROM tblC WHERE ID = @Id ...
24 Apr 2014 by _Asif_
Try below approach for your problem. Might fix your issue.DECLARE @table TABLE (id INT NOT NULL PRIMARY KEY, name NVARCHAR(4000) NOT NULL, path HIERARCHYID)INSERTINTO @tableVALUES (1, 'Root', '/'), (2, 'A', '/1/'), (3, 'E', '/2/'), (4, 'B',...
28 Apr 2014 by _Asif_
Well its hard to understand your query but we can help you debug your sql and identify which field is creating problem. You can debug your sql like this and see which field has invalid data one by oneSelect --Convert(Varchar(30),a.VIANO,113) VIANO, ...
13 May 2014 by _Asif_
We have to induct intelligence about the child precedence somewhere to get the required result. I have modified the child structure adding number (1, 2, 3) against each parent. This have resolved the query easily.DECLARE @parent TABLE (ParentNum INT, ParentName VARCHAR(50)); DECLARE...
8 Sep 2014 by _Asif_
Tough i am not happy with below solution but this could get you going.DECLARE @TBL TABLE( PARENTID INT, CHILDID INT)DECLARE @TAGERTTBL TABLE( PARENTID INT, CHILDID INT, Level int IDENTITY(0, 1))INSERT INTO @TBL(PARENTID, CHILDID)SELECT 1, 11 UNION...
8 Sep 2014 by _Asif_
Try this to get an understanding.FileStream and FileTable in SQL Server 2012[^]!
15 Jan 2015 by _Asif_
This probably seems a Duplicate SID issue. Contact Your System Administrator and ask for assistance.
27 Jan 2015 by _Asif_
Try thisDECLARE @TBL TABLE( AUTO_ID INT IDENTITY, ACTIVITY_TIME DATETIME, STATUS_ID INT)INSERT INTO @TBL(ACTIVITY_TIME,STATUS_ID)SELECT '2013-08-23T14:52:00' ACTIVITY_TIME, 15 STATUS_IDUNION ALLSELECT '2013-08-23T14:50:00' , 16UNION ALLSELECT '2013-08-23T14:45:00' ,...
29 May 2015 by _Asif_
Well you can debug your result by queries the result and see yourself what values are being qualified for update.Try running below query for each Task and validate the result. You will find anomaly in status that are causing the update to fail.SELECT @Percent [Percent], (CASE WHEN...
28 Jun 2015 by _Asif_
This seems like a homework. We won't give you a precise answer however we can give you the tip so that you could rest of the task yourself.How to use Cursor in Sql[^]
31 Dec 2015 by _Asif_
check this cool article SQL Server SUSPECT database[^] which forces a DB into SUSPECT Mode
7 Apr 2014 by _Damian S_
Leading zeros are dropped when you read the number as an integer value. You would need to operate on them as strings (varchar).
21 Jul 2015 by _Dhull
I want to update one column in LINQ to SQL. My Query is like :-private void UpdateCourse(){ OperationDataContext OdContext = new OperationDataContext(); //Get Single course which need to update COURSE objCourse = OdContext.COURSEs.Single(course => course.course_name ==...
21 Jul 2015 by _Dhull
Yes both will work fine. But which one is fast and efficient? Suppose i have 15 column in table all are varchar(max) than LINQ TO SQL first fetch all column and than update means 2 hit to DB. Which one(above mention way OR Stored procedure) is fast and preferred?
8 Jul 2015 by _Maxxx_
select from tablewhere a > 5 or b > 5 or c> 5 or d>5 or e>5if you mean ony include IDs where one of the columns is > 5replace 'or' with 'and' if you mean all columns must be > 5
8 Apr 2014 by _Starbug_
for adding a invoice no for your invoice form you can add it to top-left or top-right of your form(for example). for generating new invoice no for your new invoice you can create a string that has numbers and letters that with every click on create invoice button you can generate new invoice no...
10 Jun 2014 by A N Saraf
I'm Using SQL Server 2012 Express & VB.NetOn my development machine everything is perfect with with SQL Server 2012 LocalDB as data sourceLocaldb Connection String:"Data Source=(LocalDB)\v11.0;Integrated Security=true;AttachDbFileName=C:\TestData\Test.Mdf"On the testing machine...
16 Oct 2012 by Aadhar Joshi
As a professional, Which should be better to usestatement in stored procedure or Lock Hints in particular query..SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTEDOR SELECT DISTINCT T.CompanyID ...
17 Oct 2012 by Aadhar Joshi
I agreed Andrew Cherednik. just i want to confirm so i posted the question.Actually where i am working is a large transaction traffic and by using isolation level, sometimes u get data with dirty reads or penthoms. But as far locks are safe.
16 Nov 2014 by aarif moh shaikh
Try This............. Defiantly you will get your Solution.. Update student set student.HobbiesId=Hobbies.HobbiesId From student inner join Hobbies on student.HobbiesId=Hobbies.HobbiesIdNote: If this Solve your Problem Please click on Accept Answer.ThanksAARIF SHAIKH
25 Aug 2015 by aarif moh shaikh
Use break point and check your condition. is it true or false?i think statement is false.
20 May 2014 by Aaron Hartley
I have a C# windows application written in VS 2010 that uses SQL Server Express database as the back-end. I'm finding that I have a need for having different users with different rights, to limit how much damage can be done by careless users. For example, one highly trusted user can mass delete...
2 Jan 2014 by Aarti Meswania
this way,Select * from( Select ROW_NUMBER() OVER(ORDER BY EmpID DESC) as RowNo, Emp.EMPID, EMP.FirstName from ( Select Emp.EMPID, EMP.FirstName From Emp Union Select Emp.EMPID, EMP.FirstName ...
13 Apr 2014 by Aarti Meswania
Hi,; with Groupedsalary as( select DepartmentId , SUM(salary) as Tsalary from tblEmployee group by DepartmentId)select * from GroupedsalaryHappy Coding!:)
15 Apr 2014 by Aarti Meswania
this is second date '2014-04-09 15:39:20.000' if you write '2014-04-09 15:39' then it will be take seconds 00.000 by default so...'2014-04-09 15:39' = '2014-04-09 15:39:00.000'so, the records having RecordedDateTime greater than '2014-04-09 15:39:00.000' will not be displayedbecause...
20 Sep 2014 by Aarti Meswania
To fetch records which are in table1 but not in table2select LastName,FirstName,MiddleName,SSN Number,Nap_Id numberFrom table1EXCEPTselect LastName,FirstName,MiddleName,SSN Number,Nap_Id numberFrom table2To fetch records which are in table2 but not in table1select...
1 Oct 2012 by aasim abdullah
How do you know, if someone disabled your job at production database server. Who is the calprit. How to send a mail alert for this change ??
15 Sep 2012 by aasim abdullah
How to control SQL Server Log Information
19 Apr 2013 by aasim abdullah
Automatic query execution at every instance startup.
19 Apr 2013 by aasim abdullah
The TOP clause is commonly used to get the top required rows from a result set. The beauty of this clause is that it can be used with the WITH TIES clause to retrieve all similar rows to a base result set.
23 Oct 2012 by aasim abdullah
How to use DELETED and INSERTED virtual tables to capture data change in result of any INSERT, UPDATE or DELETE statement.
24 Oct 2012 by aasim abdullah
Backup and then restore of a database is a normal job for developers and DBAs. This script will be helpfull to findout, from which path, and which backup file a database was restored.
1 Nov 2012 by aasim abdullah
You have place indexes but still queries are slow... are you facing bookmark lookup problem ???
9 Jan 2013 by aasim abdullah
SQL Server: A Query Slow in SSMS, Fast in Application, WHY?
7 Jan 2014 by Abbas Naghdi
Hey.I want to create a report using Stimul Report 2013.But show me the error.Please help me ... How do I fix this error?My Database : SQL Express 2012Error : http://up98.ir/uploads/138917704759751.jpg[^]
9 Jan 2014 by Abbas Naghdi
I' Upgrade Stimulreport 2013 to stimulreport 2013.but this software cant connect to database ... ? !!!!
10 Sep 2015 by Abdisamad Khalif
That is simple!1- Make MenuId column primary key in your NewMenu Table 2- UserRightsId column should be foreign key to MenuId column, that is, This column should contain existing MenuIDs.3- Write SQL Query to Select NewMenu table Join it to UserRights Table where UserRights.UserID =...
8 Apr 2014 by abdul subhan mohammed
Hi guys,I have created one asp.net page for invoice, where i have to generate invoice no# before insertion.for eg, creating invoice form:Date:__________ Invoice# 10012Item:__________ Description:__________ Qty:__________Remarks:__________'Save'on every new invoice,...
9 Feb 2015 by Abhai Oza
Hello...Try thishttps://msdn.microsoft.com/en-IN/library/ms189915.aspx[^]http://www.toadworld.com/platforms/ibmdb2/w/wiki/7467.creating-stored-procedures.aspx[^]
11 Jun 2017 by Abhi1 Kanobi
I have a stored procedure that is used to send mails to a list of people . I have stored the image in varbinary(max) in my database in imagetable . I am unable to send the email along with images in body . Can anybody please help ? What I have tried: have tried adding the image in body...
16 Jun 2017 by Abhi1 Kanobi
Hello Everyone , I am trying to import multiple excel files into sql server through import wizard . The files contain a big list of names and email addresses . The problem after finishing import of one file ( I have created a ID column into destination table , auto increment ) , the rest files...
16 Jun 2017 by Abhi1 Kanobi
A lot of research proved that it's impossible . The excel files need to be restructured to fit the data , and the missing columns need to be added . I was able to insert data .
27 Mar 2014 by Abhinav S
Try these -Counting Consecutive Dates Using SQL[^]http://bytes.com/topic/sql-server/answers/861048-how-find-x-consecutive-integer-values-table-column[^]http://ask.sqlservercentral.com/questions/17524/how-to-find-records-with-3-consecutive-same-values.html[^]
5 Apr 2014 by Abhinav S
You can use the ADD function[^].E.g. select * from table where coldateofjoining > DATEADD(year, -5, GETDATE())
7 Apr 2014 by Abhinav S
TrySending/Receiving PictureBox Image in C# To/From Microsoft SQL SERVER[^]http://www.youtube.com/watch?v=5OzAJIXbfQY[^]http://www.youtube.com/watch?v=BqyAAGMfTD8[^]
21 Apr 2014 by Abhinav S
Tryselect A.name,A.col1,(select col2 from table B where A.name = B.name and col2 !=null) from table A where col1 != null
2 Jun 2014 by Abhinav S
You have not defined the column names.cmd.CommandText = "insert into " + table (colA, colB) + "values ('" + textBox1.Text + "', '" + textBox2.Text + "');";As an aside, you should look at command parameters[^].Queries like this are dangerous - SQL Injection[^].
11 Jul 2014 by Abhinav S
Correct your query -cmd.CommandText = "INSERT INTO Itens (Price) " +"VALUES (@Num)Remove the single quotes.As a note, Itens may be the wrong table(Items maybe?).
29 Jul 2014 by Abhinav S
You are correct and can do this via linked servers.Here are some examples -How to Config Linked Servers in a Minute[^]inked Servers in SQL Server 2008[^]
15 Feb 2015 by Abhinav S
SQL Server does not support varchar2. Thats Oracle.Instead use nvarchar which is equivalent to varchar2.
20 Feb 2015 by Abhinav S
Try display html content in a textbox[^].
25 Mar 2015 by Abhinav S
Try thisleft outer join navmaster_properties prop on prop.Id = (CASE WHEN (isnumeric(PD.VALUE) = 1) THEN CAST( PD.VALUEAS bigint ) ELSE 0 END))
8 Apr 2015 by Abhinav S
Your mobile number contains some special characters in between.Could be1) Spaces 1234 56 782) Hyphens 1234-56-78Thus when you try and convert this string into an integer for storing, even after the trim(), you will get an error.
18 Apr 2015 by Abhinav S
Additional links -How to debug stored procedures in Visual Studio .NET [^]Debugging SP's[^]Debugging Stored Procedures[^]
29 Jun 2015 by Abhinav S
Copy the whole data table and remove the specific columns e.g.DataTable cpy;cpy = original.Copy();cpy.Columns.Remove("OrderName");cpy.Columns.Remove("OrderDate");
29 Jun 2015 by Abhinav S
Create procedure syntax is not correctly followed. Syntax should start with CREATE PROCEDURE.Try Create a Stored Procedure[^].
4 Jul 2015 by Abhinav S
Tryhttp://www.youtube.com/wa...
7 Jul 2015 by Abhinav S
The sub query i.e.(select MAX(D.ID)as id,D.Date,D.BREMPROCODE from dataupload D where D.BREMPROCODE IN(SELECT BREMPROCODE FROM Dataupload WHERE REGIONCODE='005') AND MONTH(date)=MONTH(GETDATE()) and day(date)=day(getdate()) GROUP BY D.Date,D.BREMPROCODE )x) ) as CurrentPrice from...
8 Jul 2015 by Abhinav S
Joining the same table is possible - Self Joins[^].
17 Sep 2015 by Abhinav S
For the query editor, SQLManagementStudio_x64_ENU.exe is what you should be interested in. Pick the right version based on your OS.
21 Sep 2015 by Abhinav S
Try the following 1) drop the constraint on the table2) add the column3) add data in this column4) make a new primary key with the 5 fieldsTo get a list of constraints on the table, tryselect OBJECT_NAME(OBJECT_ID) AS constrntFROM sys.objectswhere...
9 Dec 2015 by Abhinav S
Check solutions on this thread[^].
7 Apr 2014 by abhiSek99
Hi All, How to split the below integer value in SQL query Month/Year 012013 022013 122013 I am able to split 122013 as 12 2013 but am not able to split "012013" and "022013" values.Query i used to split.SELECT left(ID, 2)...
7 Apr 2014 by abhiSek99
Hi All,Below is the table data ID1220131120131020139201382013720136201352013420133201312014i tried with the below code but its not workingDeclare @input intselect @input =ID from @tableVar IF(COUNT(@INPUT) > 6) BEGIN SELECT...
25 Jun 2015 by Abhishek Burrnwal
Change status automatically using trigger from database when system date and date(from database) are equalMy table is-:EmployeeId Status Date1 false 2015-06-25 2 false 2015-06-25 3 false 2015-06-26 4 false 2015-06-26If system date...
10 Sep 2014 by Abhishek Jaiswall
I want, SQL query for this stored procedureCREATE PROCEDURE GetJobReceivedBeyondPC(@JobReceivedBeyondPC float output,)ASBEGINdeclare @countJobsDateDiff floatdeclare @countProdcutivityCapacity floatdeclare @SumFootage float select @countJobsDateDiff= queryselect...
7 Oct 2015 by Abhishek Pant
Hi,I have two table valued functions as T1 and T2and executing this I get T1 data as ParameterID Parametername ParameterDoc 1 French French Data 2 German German Data 3 Polish Polish Data ...
13 Jun 2016 by abhishekagrwl25
Hello All,I have a scenario that I have a search form which I have to use for Update and reporting purposes, for that I have to use dynamic generated controls based on search criteria selected from dropdownlist, and according to search criteria I have to generate Textbox or Dropdownlist or...
19 Sep 2018 by AbhishekDotNet
Hi,I have a created two separate C# web application using EF6 (one with Database First and other with Code First approach). everything is going on smoothly but after sometime it is required to merge both.After merging , Database is same for Code First Approach.Initial I was using...
12 Jul 2016 by abinash panda
Declare @cSex varchar Set @cSex = (Select cSex from StaffMaster where iSMID = @iSMID) While(@iSMID
11 Apr 2014 by Abinash_Sahoo
As I can see your USP_CandidateActivation procedure is expecting as datatype of UNIQUEIDENTIFIER, but you are passing a string value for ActivationCode. That could be an issue. You may try this:db1.sqlcmd.Parameters.Add("@ActivationCode", SqlDbType.UniqueIdentifier).Value = Guid.NewGuid();
28 May 2016 by Abrar Kazi
MY TABLE Values MODEID (Col Name)0105 ...Required Output : @ModeID varchar(200) @ModeID =01,05,06,etcWhat I have tried:declare @courierModeID varchar(200) select @courierModeID = (Select DIStinct MODEID from B2B_Order_Master_SAP where ORDERNO_PORTAL='OR1206')
3 Jun 2016 by Abrar Kazi
BATCH : Qty : ProductIDB1 : 10 : 1B2 : 5 : 1B3 : 13 : 1B4 : 2 : 1B5 : 1 : 1I will pass Required Qty say 14 I want my query to find those batches whose qty ;CAse 1 = Equals required qtyCase 2 = max combination of 3 or 2...
22 Jan 2015 by Abu Zafor Khairuzzaman
Comparison Chart for Two Different Time Frames in SSRS
22 Mar 2015 by Aby Mammen Mathew
IoT devices needs the capability to augment the environment around them, even when sensors utilized by them break down
8 Jan 2015 by AdamASPGeek
Hi there,Do you have Plesk panel installed on your VPS? If yes, you just need to go to your CP--> website and domains--> database--> add new database.
6 May 2015 by AdamASPGeek
Please just use FTP tools to upload your files. Frontpage only can be enabled on Windows Server 2003. If you use Windows Server 2008 above, then you cant use Frontpage again. I also use asphostportal to host my asp.net site. I upload using FTP to root folder
19 Sep 2014 by Adapala Ashok Kumar
How to Compare 2 tables and get the Unmatched rows? But In each table there are more than 500000 records.I want to compare 2 tables by using LastName,FirstName,MiddleName,SSN Number,Nap_Id number, and DateOfBirth ?
2 Aug 2013 by Adarsh chauhan
Try thisupdate tableNameset ColumnName= replace(ColumnName, 'Fruits -', '')or if just want to selectselect replace(ColumnName, 'Fruits -', '') from TableName
1 Jul 2015 by Adnan Malikk
--- From whatever i can understand from your question above DECLARE @count INTDECLARE @I INTDECLARE @PackageVar NVARCHAR(100)DECLARE @Loop INTSET @Loop = 100SELECT @I = 1SELECT @count = COUNT(PackagePeriod) FROM #tempWHILE (@I
21 Dec 2016 by Advay Pandya
You can use IsNULL in this case.So your query will look as below:Select case when UpdatedDate is not null then UpdatedDate when InsertedDate is not null then InsertedDate else VisitedDate endFrom tbl_UserTrackingwhere Isnull(UpdatedDate,Isnull(InsertedDate,VisitedDate)) between date1...
2 Aug 2014 by Afzaal Ahmad Zeeshan
If you want to build a webite, then I guess you can do that using ASP.NET Web API. ASP.NET Web API has got a solution for your requirement and you can implement it to your Application too. You can develop the ASP.NET Web Site using MVC architect and then add the Web API. Android application...
2 Jul 2015 by Afzaal Ahmad Zeeshan
Unicode is supported in .NET framework, and you can easily use Unicode's UTF-8, UTF-16 or other encodings (or character sets) of Unicode in your applications. The thing is that you need to be sure whether your application is able to represent the glyphs or not. If you application's font family...
4 Jul 2015 by Afzaal Ahmad Zeeshan
What you are looking for is UPDATE clause. UPDATE clause allows you to update a particular record (or all records if you do not append WHERE clause). So, for example you would run the query 11 times and update the records like this, UPDATE table_name SET Country = 'India'WHERE...
8 Jul 2015 by Afzaal Ahmad Zeeshan
Look into backups of your SQL Server, if you have made any. SQL Server would be able to back up the data to previous state. You should not use any tools, as they might make things even worse. Instead, you should always be careful in your acts. If there were no back ups created, then no you...
20 Jul 2015 by Afzaal Ahmad Zeeshan
You are mixing a combination of Bad UX and Bad UI in your web application. First of all, you are well aware that web applications need network traffic so sending this much huge data (even if this takes 5 MB of network size) would never be a good idea. Pagination is used to minimize the network...