SQL Server

MVC insert update delete and select records

CRUD (Create, Retrieve, Update and Delete) in MVC. When we start to learn new language, first we try to run an application with “Hello World” and then CRUD functionality. So in this article we will see how to select records from database (with WebGrid, pagination and sort functionality), update a record, add new record and finally delete a record in ASP.Net MVC. Let’s create a simple table... By Ali Adravi   On 17 Aug 2013  Viewed: 71,933
  • mvc
  • asp.net
  • sql server

Could not load file or assembly Microsoft.SqlServer.Management.Sdk.Sfc

Try to add ADO.Net Entity Data Model by using Visual Studio 2013 and having SQL Server 2008 R2 and got the error "Unable to add data connection.", so change my mind and try the same by using Linq to SQL Classes and again go the same error. As usual I try some other options to connect to the database but still the error message is same so decided to explore to fix it. Here is the complete... By Ali Adravi   On 06 Nov 2014  Viewed: 15,226
  • sql server
  • vs 2012
  • vs2013

Bulk insert with text qualifier in sql server

Bulk insert with text qualifier from a text or csv file into sql server can be achieved by using a format file, in format file we can define the sequence of columns in source file (txt or csv file), data type, length, destination table column, version and number of columns, we will see everything in detail with different examples Suppose we have to import following file to our database ... By Ali Adravi   On 10 Jun 2013  Viewed: 14,049
  • bulk-insert
  • sql server
  • csv

Bulk insert into SQL Server from CSV file by skipping first row

Bulk insert is used to Import a data file into a database table or view in a user-specified format. It's not daily using kind of code, so it's very common question on most of the site like. How to import CSV file into a table? How to insert records from a CSV file to a table, delimited by comma? How to load CSV file to SQL Server database? We will discuss here the same but with more detail, so... By Ali Adravi   On 08 Feb 2013  Viewed: 12,146
  • bulk-insert
  • sql server
  • csv

How to retrieve data from database using JavaScript in asp.net

I was checking how to validate a user email from database without post back, using JavaScript. After some search and RND found the way to call the web service method with the help of Ajax and JavaScript. Let’s say we have a registration page on which we accept email from the user and we expect it should be unique in entire database. So we need a method to immediately validate the email from... By Ali Adravi   On 24 Jun 2012  Viewed: 9,857
  • javascript
  • sql server
  • asp.net

SSRS subreport with drill down step by step in sql server 2008

sql reporting subreport with toggle To create a toggle sub report in sql reporting service is too easy but if you will not aware about it then it is really difficult for you. So in this article we will see how to create a report with having sub report, and sub report data will load only when we will toggle (0pen) the sub report and not on the load of main report. To learn basic of reports see... By Ali Adravi   On 09 Sep 2013  Viewed: 7,611
  • ssrs
  • report
  • sql server

Concatenate multiple columns in SQL Server with NULL value

When we need to concatenate two columns simply we can use `+` sign and that is correct, but what if any of them is null, Will it return what we want, NO, it will return null. So let's discuss how we should concatenate two or more columns without creating extra space or extra comma problem. Let's say we have a customers table with following structure and data ![alt text][1] Now suppose we... By Ali Adravi   On 13 Feb 2013  Viewed: 4,626
  • sql server

SQL transaction status and XACT_STATE()

XACT_STATE() is a scalar function that gives the user transaction state of a current running request. It indicates whether the request has an active user transaction, and whether the transaction is capable of being committed or not. XACT_STATE returns the following three values - **1**: The current request has an active user transaction. The request can perform any actions, including... By Ali Adravi   On 28 Dec 2012  Viewed: 3,332
  • sql server

SQL ISNULL, IFNULL and NVL function with example

ISNULL in Sql Server is uded to check and return alternate value if value is NULL, while to only check the NULL value, we can us IS NULL with space, in MySQL and Sqlite, for same functionality, we can be use IFNULL and in Oracle we can use NVL. Suppose we want to return 0 if column value is null then we can use select ISNULL(columnName, 0) from table_name Column type and alternate... By Hamden   On 31 Aug 2013  Viewed: 2,134
  • sql server
  • mysql
  • sqlite

How to use comma separated Ids as parameter in sql server?

just think to pass comma separated Id as a parameter or how to use comma delimited value as parameter and use that in SQL server, since there is no way to use parameter as an array so we can use string for multiple IDs or values but if it's integer then we cannot use it in IN clause in SQL Server even if it is string (varchar). So how to use multiple values or IDs as parameter and use that in IN... By Ali Adravi   On 02 May 2013  Viewed: 1,491
  • sql server

Get precision and decimal value in SQL Server by using PARSENAME

In SQL server there are decimal and money data type to store precision and scale both together or say decimal values. Suppose we want to get precision and scale separately then how to get it. There are many ways to do this but there is a function in SQL named PARSENAME which can be used to get our result, see this Declare @price Decimal(10,2) Set @price=12345678.90 Select... By Myghty   On 26 Mar 2013  Viewed: 1,089
  • sql server
  • parsename

Create procedure with default value parameters

When we create function we can use default value for parameters if we need so, is there any way to create a procedure with default value parameter in SQL Server so when we don’t pass the value for that parameter they can use default values? Yes, we can. In this article we will create procedure with default parameter value. Let's see default template provided by microsoft: SET ANSI_NULLS... By Ali Adravi   On 14 May 2013  Viewed: 846
  • sql server
  • procedure

Change column name and data type in Sql Server

How to change column name and data type of a column cannot be done in one statement but first we need to change the column name and then data type, In this post we will check many other things like how to change data type of a column, how to drop a column, how to add a new column, how to make a column not nullable etc. So first we will see how to change a column name as well as data type of... By Hamden   On 05 May 2013  Viewed: 685
  • sql server

Delete duplicate records in sql for specific columns

Delete duplicate records from table is the very common question and task we need in our day to day life, so we will see how easily we can delete duplicate records from a table by using subquery and using partition by function supported by Sql Server 2005 and later version. Say the table name is Address, having following records AddressID CustomerID Address City Zip Country 1 ... By Ali Adravi   On 26 Aug 2013  Viewed: 681
  • sql server

Sql reporting services first report

SQL Reporting services also known as SSRS is a great tool to create report from database. In this article we will learn how to create a basic Report. We will learn how to create a shared data source so we can use it for all the reports in our project, How to create our data set to bind columns in report. For advanced report see my other article [SSRS subreport with drill down step by step in sql... By Ali Adravi   On 10 Sep 2013  Viewed: 628
  • ssrs
  • report
  • sql server

Parameterized view in SQL Server with example

Parameterized view means we can pass some value to get the data from the view the table by using view. The parameter accepts values that can be supplied later by prompting the user or programmatically, it is possible in MS-Access and FoxPro but is it supported in SQL Server? Answer is big NO, but there are ways to achieve the same feature, which we will discuss in this article. By using view... By Ali Adravi   On 07 Sep 2013  Viewed: 621
  • sql server
  • cte
  • udf

update multiple table with transaction between try catch in sql server

I need to create script for entire database changes every week for my client to run on production server, when I was creating the script I need to check whatever I have created so I try to use transaction and to roll back every change, so I used try catch but it inserted many records in some master tables while there was some error in script and still error was not catching by try catch where i... By Hamden   On 11 Oct 2013  Viewed: 616
  • sql server
  • try..catch

SQL COUNT Function with example

Count function takes one parameter and returns the number of rows for the matching criteria. Select Count(*) From employees It will return count of entire records into Employees table, same result can also be get from following sql statement Select Count(1) From employees In this statement we used, 1 in place of *, there are discussion about count(*) and count(1),... By Hamden   On 31 Aug 2013  Viewed: 546
  • count
  • sql server

Conditional where clause in SQL server and tricks

*Suppose you want to search the records on the basis of start and end date and for that if ModifiedDate is not null then use it otherwise use the Creation date:* Simply we can use, if in where clause like this If ModifiedDate IS NULL Where CreationDate Between @StartDate And @EndDate Else Where ModifiedDate Between @StartDate And @EndDate If there... By Ali Adravi   On 14 Jul 2012  Viewed: 500
  • sql server

some useful sql tricks

There are many ways which can help us to save our time to write some repeated code or to do some repeated action, in this post we will see some very common code which we need very frequently in our development life. I am not saying that after this post you will save your half say work every day but hope fully you will get something for you which can may you happier, so let’s start one by... By Ali Adravi   On 31 Mar 2013  Viewed: 463
  • sql server
12