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


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

how to remove row in select statement

Posted By:      Posted Date: October 17, 2010    Points: 0   Category :Sql Server
 

Hi All,

I want to write select statement

Requirement is

There is one table in database ,I am using function also in select statement

Here is the query

select 'policy' as 'Identifier ',(case substring (col1,2,1) when 'G' then 'Good'

                                                                             when 'B' then 'Bad'else null end) as status,

case function1(col1,loandate) when 'no identify' then ' else

function1(col1,loandate)+substring(col1,2,1) as ID from table 1

when I am running this query ,getting

Identifier           Status                     ID

Policy              Good                  &nb


View Complete Post


More Related Resource Links

web services transactions (select statement)

  
 Hi everybody, i'm just getting started in web services and i have a problem connecting to a database. All i want is that my web service recieves a string parameter and return a dataset so that in the client aplication i just show the result of the web service in a datagrid. Here's the code of the web service:    <%@ WebService Language="C#" CodeBehind="Service1.asmx.cs" %> using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Linq;using System.Web;using System.Web.Services;using System.Web.Services.Protocols;using System.Xml.Linq;using System.EnterpriseServices;using System.Data.SqlClient;namespace Farmacia{    [WebService(Namespace = "http://localhost/MyWebServices")]    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]    [ToolboxItem(false)]    public class Farmacia : System.Web.Services.WebService    {        private SqlDataAdapter da;        [WebMethod(TransactionOption=TransactionOption.RequiresNew)]        public DataSet Consultas (string sel)        {            if (sel == "")&

SQL DIAGOSITC MANAGER tools capture "SELECT *" statement while ALTER / ADD CHECK CONSTRAINT is execu

  
Hello  ,   I exectuted the code(alter/add with check)  below in SSMS . My_table has 200 millions records . While running the alter/add with check query  the server crashed and the “SQL DIAGOSITC MANAGER” which run on the top of sql serever alert the DBA that select * from my_table was obtained from the last command issued by the user using a DBCC command.      Where does the select * from my_table comes from ? I didn’t excuted select * from my_table at all .   After the sql serever re started I was able to run the command below with out any problem. I checked the SQL PROFILER for the trace there is no “select * from my_table” .   So again where this select * from my_table comes from ?   Here is my initial query ----------------------------------------------------------------- ALTER TABLE [Dbo].my_table WITH CHECK ADD  CONSTRAINT [FK_key1] FOREIGN KEY([Key1]) REFERENCES [Dbo].[Dim_table1] ([Key1]) GO   ALTER TABLE [Dbo].my_table CHECK CONSTRAINT [FK_key1] GO   ALTER TABLE [Dbo].my_table WITH CHECK ADD  CONSTRAINT [FK_key2] FOREIGN KEY([key2]) REFERENCES [Dbo].[Dim_table2] ([key2]) GO   ALTER TABLE [Dbo].my_table CHECK CONSTRAINT [FK_key2] GO   ALTER TABLE [Dbo].my_table WITH CHECK ADD  CONSTRAINT [FK_key3] FOREIGN KEY([d], [c], [r], [g]) REFERENCES [Dbo].my

SELECT statement to return NULL by matching data from another table.

  
Hi,I am fairly new at SQL and I have been struggling for days now trying to find an answer to my problem and i have come to the point where i have run out of ideas and about to give up. I'm hoping someone can put me in the correct path. The problem I have 3 table Table 1 Department" has the following columns: REF, NAME Table 2  "Department_Collection" has the following columns: REF, DEPARTMENT_REF, MANAGER_REF, STORE_REF, ACTIVE Table 3 Store" has the following columns: REF, NAME, STORE_ID  What i am trying to do is to take all the rows in the Department table and get a matching row (DEPARTMENT.NAME, DEPARTMENT_COLLECTION.REF) from the Department_Collection table, if it does not match any then still display DEPARTMENT.NAME but mark DEPARTMENT_COLLECTION.REF as null. I have tried the following select statement but it seem to remove all null values when supplied with a 'storename' SELECT DEPARTMENT.NAME, DEPARTMENT_COLLECTION.REF FROM DEPARTMENT_COLLECTION right outer join DEPARTMENT on DEPARTMENT_COLLECTION.DEPARTMENT_REF = DEPARTMENT.REF left outer join STORE on DEPARTMENT_COLLECTION.STORE_REF = STORE.REF where STORE.NAME = 'storename' order by DEPARTMENT.NAME   Any help will be greatly appreciated. Thanks

Can we use Select clause in Case statement

  
SELECT CASE OT.ItemTypeID WHEN 6 THEN SELECT SUM(ISNULL("Item Cost",0)) FROM SUBTABLE IT WHERE IT.OrderID = OT.OrderID AND IT.ItemTypeID IN(6,11,12) WHEN 7 THEN SELECT SUM(ISNULL("Item Cost",0)) FROM SUBTABLE IT WHERE IT.OrderID = OT.OrderID AND IT.ItemTypeID IN(7,14,15) WHEN 8 THEN SELECT SUM(ISNULL("Item Cost",0)) FROM SUBTABLE IT WHERE IT.OrderID = OT.OrderID AND IT.ItemTypeID = 8 WHEN 9 THEN SELECT SUM(ISNULL("Item Cost",0)) FROM SUBTABLE IT WHERE IT.OrderID = OT.OrderID AND IT.ItemTypeID = 9 WHEN 10 THEN SELECT SUM(ISNULL("Item Cost",0)) FROM SUBTABLE IT WHERE IT.OrderID = OT.OrderID AND IT.ItemTypeID = 10 WHEN 11 THEN SELECT SUM(ISNULL("Item Cost",0)) FROM SUBTABLE IT WHERE IT.OrderID = OT.OrderID AND IT.ItemTypeID IN(6,11,12) WHEN 12 THEN SELECT SUM(ISNULL("Item Cost",0)) FROM SUBTABLE IT WHERE IT.OrderID = OT.OrderID AND IT.ItemTypeID IN(6,11,12) WHEN 14 THEN SELECT SUM(ISNULL("Item Cost",0)) FROM SUBTABLE IT WHERE IT.OrderID = OT.OrderID AND IT.ItemTypeID IN(7,14,15) WHEN 15 THEN SELECT SUM(ISNULL("Item Cost",0)) FROM SUBTABLE IT WHERE IT.OrderID = OT.OrderID AND IT.ItemTypeID IN(7,14,15) WHEN 18 THEN SELECT SUM(ISNULL("Item Cost",0)) FROM SUBTABLE IT WHERE IT.OrderID = OT.OrderID AND IT.ItemTypeID = 18 WHEN 19 THEN SELECT SUM(ISNULL(&qu

How do i use the select statement in functions?

  
hi friends, i have table-value function, but the has the bug in the body and i cannot debug, becuase it does not allow the select statement in it. is there away to print values to the screen, when debugging? PS: in not using a SP to debug it thanks

Assistance with SELECT statement requested

  
Hi All, I am having trouble getting started on writing a select statement to meet the following requirements.  I have a table with Employee Ids, address types, and address information.  I would like to obtain one record for each EmplID based upon the Type column; the PRF type record if it exists, otherwise then the PRI record.  (See Table A) TableA Rcd #, EmplID, Type, Address Data 1, 000001, PRI, etc 2, 000001, PRF, etc 3, 000002, PRI, etc 4, 000003, PRI, etc 5, 000003, PRF, etc 6, 000003, OTH, etc So, my result set from the table above would be: 2, 000001, PRF, etc 3, 000002, PRI, etc 5, 000003, PRF, etc What is the best way to obtain this information via a SELECT statement?  Thanks in advance, Steve  

Get output from storedprocedure and assign in Select statement

  
Is it possible to get the output from stored procedure and assign into select statement. for example. Here prc_GetComplete is another storeprocedure to get the value for @Completes INSERT INTO TABELE1 (ID, address, completes ) SELECT NEWID(), t2.address, @Completes = EXEC prc_GetComplete t2.ID , @Completes OUT FROM TABELE2 t2   Regards, teesh

ODBC Select if Statement in MAS90 query

  
Hi, I am connecting to a MAS90 database via DSN and am having trouble with the query string for ODBC.  I can collect most all fields if I SELECT them directly, however, I want to create a result column based on which cost is higher. As far as I know, this select statement in to and ODBC connection needs to comply with MSSQL I have tried SELECT IM1_InventoryMasterfile.ItemNumber, IFF(IM1_InventoryMasterfile.LastCost > IM1_InventoryMasterfile.AveCost,IM1_InventoryMasterfile.LastCost,IM1_InventoryMasterfile.AveCost) as 'Cost', IM1_InventoryMasterfile.TotalQtyOnHand FROM IM1_InventoryMasterfile IM1_InventoryMasterfile And SELECT IM1_InventoryMasterfile.ItemNumber, CASE WHEN IM1_InventoryMasterfile.LastCost > IM1_InventoryMasterfile.AveCost THEN IM1_InventoryMasterfile.LastCost ELSE IM1_InventoryMasterfile.AveCost END as 'Cost', IM1_InventoryMasterfile.TotalQtyOnHand FROM IM1_InventoryMasterfile IM1_InventoryMasterfile Neither are working?  What am I missing here? Can I do this sort of if then statement in MSSQL?   Thanks for your help 

Select statement

  
Hi All. Greetings. I have 2 tables.Table =Person ID Person ---------- ----------- 1 ali2 abuTable = DetailID Person_ID fakeID---------- ----------- --------------1 1 442 6 553 2 66select * from person, detail where person.id=detail.person_id and fakeID=55I want it show me record of 55 because of Person_ID 6 is not in Table Person and i am using operator AND,so It is not showing any thing.But i want, it show me record of 55 so what i change in this statement or which opertor i use .... so it show me.select * from person, detail where person.id=detail.person_id and fakeID=55I mean i want if value 6 in the (table Person) it show me the name of Person, but if ID 6 or value 6 not there even it show mebut show me empty place of name. Because 6 i required. ID Person ---------- ----------- 6 Any if there is 6 in the (Table Person) then ID Person ---------- ----------- 6 Rubi Thanks Advance

Textbox -> Value -> Gridview -> Select Statement

  
Hi guys. I have textbox that searches for first or last name. Result show in gridview. But when add value in text box and push my button Find nothing happen. Here code:aspx:........ <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="MobileNum" DataSourceID="SqlDataSource5" style="font-family: Verdana" onselectedindexchanged="GridView1_SelectedIndexChanged"> <Columns> <asp:BoundField DataField="FNAME" HeaderText="FNAME" SortExpression="FNAME" /> <asp:BoundField DataField="LNAME" HeaderText="LNAME" SortExpression="LNAME" /> <asp:BoundField DataField="MobileNum" HeaderText="MobileNum" ReadOnly="True" SortExpression="MobileNum" /> <asp:BoundField DataField="HomeNum" HeaderText="HomeNum" SortExpression="HomeNum" /> <asp:BoundField DataField="OfficeNum" HeaderText="OfficeNum" SortExpression="OfficeNum" /> <asp:Bo

How to read excel header name and put into SELECT statement?

  
Hi,        I'm trying to read Excel file header column name. Then I can query data from excel using SELECT statement. For instance. column name is name, department and email.  Then I want this three header name being detected using code and put in select statement. User no need to care about the header name and we can use code to read the header name instead of hardcode header name inside SELECT statement.       Please provide the details. Thanks.

SQL SERVER 2000 Using IIF in SELECT Statement

  
Hi Good Guys, I need your help, Please help me. I am trying to retrieve data from SQL SERVER 2000 Table, TBLSupplier whose ActiveStatus datatype is BIT which consist of value 0 (zero) or 1 (one).  to display on the VBNT2008 DataGridView. But the SQL String Select statment is not working. Error message: Incorrect syntax near '=' Select SupplierId, SupplierName, IIF (ActiveStatus =1, 'YES', 'NO') as [Status] from TblSupplier

Sql Server Select statement

  
selet * from customer where status&1 = 1 what is meaning for & update customer set status = staus | 1 what is meaning for |

What is fastest way of reading large size XML in SQL Server 2005 using Select statement ?

  
What is fastest way of reading large size XML in SQL Server 2005 using Select statement ?

Parameter For Select Statement

  
I Am Working On A Project,I am using MVC, VS 2010, SQL 2005, Model Is Created Using LINQ TO SQL (.dbml)Table Joining Code in My Controller Looks Like Thispublic ActionResult Index() { var DataContext = new SMSAPPDataContext(); var result = from t in DataContext.tbl_teachers from e in DataContext.tbl_teacherenrollments from b in DataContext.tbl_batches from c in DataContext.tbl_classes from s in DataContext.tbl_subjects where t.Teacher_ID == e.Teacher_ID && e.Batch_ID == b.Batch_ID && b.Class_ID == c.Class_ID && e.Sub_ID == s.Sub_ID && c.Class_Name == "TEN" && c.Class_Section == "C" && t.Teacher_Name == " ABC " select c; return View(result.ToList()); } This Table Join QUery Gives Me Data From On Table with Select Statement.And My Inherit Page In View Looks Like This<%@ Page Title="" Language=&quo

Select statement syntax

  
Hi guysi am kinda stuck and im sure you can help mei have the following code to add stuff in my database Try Dim cmd As New SqlCommand("INSERT INTO Patient_Basic_Info(PatientID,Patname,Patlastname,DOB,Tel,ErTel,EmailAd,Adress,Insurance,Vdate) VALUES('" + PatID.Text + "','" + Patname.Text + "','" + Patlast.Text + "','" + DatePicker1.SelectedDate + "','" + Pattel.Text + "','" + PatERTel.Text + "','" + Patmail.Text + "','" + PatAddress.Text + "','" + insurancebox + "','" + DatePicker2.SelectedDate + "')", conn) conn.Open() cmd.ExecuteNonQuery() conn.Close() Label1.Visible = True Button1.Visible = False Catch ex As Exception 'handle exception here Label23.Text = ex.Message Finally If conn.State = ConnectionState.Open Then conn.Close() End If conn.Dispose() End Try Now i want a select statement to assign the Name column to a variable where the Vdate = a textbox in my formbasically i want the program to return the Name of a person in my database based on the value in another textbox. I know it doesnt make much sense

In SSRS 2005 in y-axis i want to display only those dates which are coming from select statement one

  
For example in select statement:   select date  from Employee   Now i want to show only this date field in y-axis in ssrs 2005, how can i resolve this issue?
Categories: 
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