Skip to main content

Posts

Showing posts from 2015

Determine the safe sequence of Banker's algorithm

process      Allocation   Max   Available ---------    ------------   ------   ----------- p0             3                 6         2 p1            4                 8       p2            0                 1     p3            3                 5 p4    ...

How to show CrystalReport as and Download it in MVC

As there is no way till now to show crystal report in a view(MVC). You can simply convert the report document as pdf using following code:  public void ShowReport()         {             List<ToDos> lstTodos = new List<ToDos>();             lstTodos = db.ToDos.ToList();             ReportDocument rd = new ReportDocument();             rd.Load(Path.Combine(Server.MapPath("CrystalReport1.rpt")));             rd.SetDataSource(lstTodos);             Stream stream;             stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Portable...

How To Compute MAX(AVG(Field)) in SQL

Suppose you have the following table You need to find which Department has the maximum average salary in a single query you can easy ly find average value of each department using aggregate function AVG() But how to select only the department having the maximum average salary.In SQL SERVER USE    select top 1 DeptName,MAX(MyAvg) AVARAGE_SALARY FROM(   select AVG(salary) as MyAvg,DeptName  from [SalaryTable] group by Deptname   ) temp   GROUP BY DeptName   order by AVARAGE_SALARY  desc 

HTTP Error 404.17 - Not Found The requested content appears to be script and will not be served by the static file handler.

Register asp.net again....will solve the issue. Go to Visual Studio Command Prompt, And register asp.net as windows\microsoft.net\Framework[.Net version num]\aspnet_regiis.exe -i AND I had this issue with Windows Server 2012 with ASP .NET 4.5 you can't use aspnet_regiis.exe, and just have to install ASP .NET 4.5 via the Add Roles and Features Wizard: and use correct application pool

Loop through all the tables within a database to perform specific task using sp_MSforeachtable in SQL Server 2012 /2008

Beginning There are some situation when we need to perform a specific task allmost every table within a database so we need to loop through all tables in a database.Let we have to truncate those tables having name with a perticular prefix or we want to count rows of each table. this article will give a tips to do this task easily using 'sp_MSforeachtable' Stored Procedure. Details 'sp_MSforeachtable' Stored Procedure is an undocumented procedure takes place in 'master' database Syntax of using 'sp_MSforeachtable' use [database_name] exec sp_MSforeachtable @command @command is the command that has to be applied in each table Example To create a list of all tables with their row count you may create a user defined stored procedure as follows CREATE PROCEDURE [dbo].[usp_RowCountForAllTables] AS BEGIN         SET NOCOUNT ON; DECLARE @TableRowCounts TABLE ([TableName] VARCHAR(128), [RowCount] INT) ; INSERT INTO @TableRowCounts ([TableNa...

Search Entire Database for a value or part of a value in SQL Server using Stored Procedure

In my recent job where I am acting as a Jr. Software Engineer .This company works for Educational institution hence their product EMS(Education Management System) .Once I was asked to find a ID of a student in entire database (which has a at least 300 tables)  and this type of task has to perform frequently .So I decided to write a Stored Procedure And it works fine. Code is Given Below: USE [yourdbname] GO /****** Object: StoredProcedure [dbo].[SearchAllTables] Script Date: 1/21/2015 11:52:21 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROC [dbo].[SearchAllTables] ( @SearchStr nvarchar(100) ) AS BEGIN DECLARE @Results TABLE(ColumnName nvarchar(370), ColumnValue nvarchar(3630)) SET NOCOUNT ON DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110) SET @TableName = '' SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''') WHILE @TableName IS NOT NULL BEGIN SET @...