.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

write a if condition in where clause

Posted By:      Posted Date: October 04, 2010    Points: 0   Category :ASP.Net

hi, my sql query gives me all record when i  am not passing  " lastname" in parameter


ALTER PROCEDURE [dbo].[Usp_LeadSearch]
@FirstName varchar(20)='',
@LastName varchar(20)=''

                set @FirstName=null
                set @LastName=null

    select L.Leadid,(L.FirstName+' ' + L.LastName) as name,LS.LeadSource,LStatus.LeadStatus,L.LeadOwner,(UM.FirstName+' '+UM.LastName)as OwnerName,convert(varchar,L.CreatedDate,110)as CreatedDate,L.IsActive,AM.ActivityType,AT.ActivityName,AM.CreateDate as activitydate
    from LeadMast L left join ActivityMast AM on L.Leadid=AM.Leadid
                    join LeadSource LS on LS

View Complete Post

More Related Resource Links

Write select query with a paremetrized where clause, and populate database with the retrieved column

I want to be able to retrieve column values using the dropdownlist values as parameters then populate the tbPO table with the retreived values. Where and how do I do it. ImportsSystem.Data.OleDb ImportsSystem ImportsSystem.IO Imports ?directcostDataSetTableAdapters PartialClass po_header  Inherits System.Web.UI.Page  Dim cn As OleDbConnection  Dim cmd As OleDbCommand  Dim dr As OleDbDataReader  Dim icount As Integer  Dim str As String  Dim vendor_id As Object   ?  Public Sub btn_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.ClickTry   context.Items.Add(     cmd.CommandType = System.Data.   cmd.CommandText = Dim context As HttpContext = HttpContext.Current"Company_Name", DropDownList3.Text)Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\Owner\Documents\Visual Studio 2010\WebSites\WebSiteJun25\App_Data\directcost.mdb;")Dim cmd As New OleDbCommand()CommandType.Text"insert into tbPO(ponumber, suppliername, ShipTo, basictype, DateNeeded, Purpose,ShippingInstr, ProjId) values(?,?,?,?,?,?,?,?)" cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.Add

Query help to write case statement in Where clause?

Hi All, I have table something like this:- SELECT UserName, IsManager FROM Employee IsManager has only two values either 1 (which means user is a Manager) or 0 (which means user is not a Manager) Now I want to write below query:- DECLARE @IsManager INT SET @IsManager = 2 SELECT UserName, IsManager FROM Employee WHERE IsManager = CASE WHEN @IsManager = 1 THEN 1 WHEN @IsManager = 0 THEN 0 WHEN @IsManager = 2 THEN 1 | 0 ----- THIS IS NOT WORKING, when I set @IsManager value to 2 then where clause should be like this "IsManager = 1 OR IsManager = 0" END Can anybody help me out in modifying about query so that it produces both the results when @IsManager variable value "2". Thanks Regards, Kumar

How to write a trigger when given a condition in SQL SERVER 2005?


Hi Guys,
I am using SQL SERVER 2005.

I know how to write a trigger for a basic insert or update or delete. But here in my case I have to use the below condition and create a trigger.

I havent used any trigger till now in my job. So I am facing a slight problem in understanding and writing the code.....
I got the following requirement to create a new trigger for the following scenario :

The user (john) should be notified when the following happens :

Any transaction entered to account 100 which is not a ABN,CCH,or TTW
Any transaction entered to account 189 which is not a KHD

Description of fields :
100 and 189 are values for AccountCode Column in Account Table
ABN,CCH,TTW and KHD are values for CompanyTypeCode Column in Company Table.
I need to create new trigger on DLT_Data table

Write Custom WebParts for SharePoint 2007

The popularity of SharePoint Portal Server 2003 led Microsoft to tightly integrate the next SharePoint version, Microsoft Office SharePoint Server (MOSS) 2007, with its ASP.NET 2.0 WebPart framework. This tight integration enables the ASP.NET and SharePoint developer to do a number of things that previously weren't possible

Power of using Clause in SharePoint

The Using Clause will help to avoid memory leaks in SharePoint by automatically Disposing the MOSS objects.

For example when we create SPSite and SPWeb objects, if we don't dispose it explicitly it might create memory leaks,

Serial Port Communication Read and Write using C#.net

In this simple article you will learn that how you can Open and read COM port data using System.IO.Ports Namespace.
Simply just create New Project of windows application in C#.

Import ServiceProcess APIs
using System.IO.Ports

Imports System.IO.Ports

Write Parsing functions which parse port data according to attached device

How to write SQL Datasource programatically in VB


Can someone pls help me to rewrite this programatically!


<asp:SqlDataSource ID="DS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="SELECT * FROM [Products] WHERE ([ProductID] = @QSID)">
                    <asp:QueryStringParameter DefaultValue="" Name="QSID" QueryStringField="ID"
                        Type="Int32" />


Thank You in advance!


How to write xml file?


I am having a three text box. I want to write the fields given in text boxes to xml file and the xml file should be open as save dialog box for the user to download the xml file. I want without saving the xml file in the physical path of the server 
Any idea let me know?


I am having a three text box. I want to write the fields given in text boxes to xml file and the xml file should be open as save dialog box for the user to

How to write in .dbf file with c#


Hi all

can anybody help me to solve my problem : writing in .dbf  , as following is my code with this error :

[ ERROR [07002] [Microsoft][ODBC dBase Driver] Too few parameters. Expected 3 ]


SqlConnection cn = new SqlConnection("Data Source=(local);Initial Catalog=test;Integrated Security=True");
        SqlDataAdapter da = new SqlDataAdapter("select * from test", cn);
        DataSet ds = new DataSet();
        da.Fill(ds, "test");
        string odbccon = "Dsn=TEST.DBF;dbq=E:\\FOX;defaultdir=E:\\FOX;driverid=533;fil=dBase 5.0;maxbuffersize=2048;pagetimeout=5";

        OdbcConnection connection = new OdbcConnection(odbccon);
        OdbcCommand createCommand = connection.CreateCommand();

        createCommand.CommandText = "CREATE TABLE test (ID int, name varchar(50),last_name varchar(50))";

Willing to Write Urdu in my text box


 hi want to write urdu in text box of my application if anyone has the solution how to do this kindly let me know

Crystal Report gives System.AccessViolationException: Attempted to read or write protected memory. T


when a crystal report for same id is opened again at same time or refreshed then it gives the

"System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Stack Trace is :-

Stack Trace:

[AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]
CrystalDecisions.ReportAppServer.Controllers.DatabaseControllerClass.SetConnectionInfos(ConnectionInfos ConnectionInfos) +0
CrystalDecisions.CrystalReports.Engine.Table.ApplyLogOnInfo(TableLogOnInfo logonInfo) +362
CrystalDecisions.CrystalReports.Engine.ReportDocument.SetTableLogon(Tables tables, String user, String password, String server, String database, Boolean ignoreCase) +258
CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDatabaseLogon(String user, String password, String server, String database, Boolean ignoreCase) +204

how to multiple condition in if statement in asp.net C#



i am using if condition to find out a time

if(time=="08 AM)


response.write"shift A";


but problem is how can i put multiple condition in if like

if(time=="06 AM" and "08 AM" and "07 AM")

{ End Bracket }: Engineers Who Write


Writing is good exercise for developers and software engineers. Richard Ward explains how writing can help you focus your thoughts and communicate more precisely.

Richard Ward

MSDN Magazine November 2008

Write On!: Create Web Apps You Can Draw On with Silverlight 2


We build a Silverlight 2.0 application using the InkPresenter to let users annotate a pre-defined collection of images, perform handwriting recognition, and save the annotations and recognized text into a server-side database.

Julia Lerman

MSDN Magazine August 2008

Mobile WCF: Write an IM App with the .NET Compact Framework


The .NET Compact Framework 3.5 provides a subset of Windows Communication Foundation (WCF) functionality that you can harness to communicate between Windows Mobile devices and desktop PCs. We'll show you how.

Andrew Arnott

MSDN Magazine Launch 2008

Share Code: Write Code Once For Both Mobile And Desktop Apps


If you're building .NET client apps already, target them to Windows Mobile using the same skills and toolsets.

Daniel Moth

MSDN Magazine July 2007

.NET Profiling: Write Profilers With Ease Using High-Level Wrapper Classes


Here Joachim H. Fröhlich and Reinhard Wolfinger show you how to get all the great functionality of the .NET Profiling API the easy way, with custom wrappers.

Joachim H. Fröhlich and Reinhard Wolfinger

MSDN Magazine April 2006

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend