Create SP that returns value and at the same time displays query result in output window

I would like create an SP which will return the records from the table and also return value to my c# client application.
For Example:
Select * from employee returns all the query results in output window.
Now I want to create an SP
Create procedure Test
As
Declare @ret int,
Select * from employee
set @ret = Select count(*) from employee
if @ret > 0
return 1
else
return 0
The above algo should return 1 0r 0 to c# client application and at the same time display all employees in sql query output window.
Can u pls help in this regard.

The above algo should return 1 0r 0 to c# client application and at the same time display all employees in sql query output window.
Why?  and No!
Why?  Your procedure generates a resultset of some number of rows.  You check the resultset for the presence of rows to determine if "anything is there".  You don't need a separate value to tell you this.  Note that it helps
to post tsql that is syntactically correct.   While we're at it, if you just need to know that rows exist there is no need to count them since that does more work than required.  Simply test for existence using the appropriately-named function
"exists".  E.g., if exists (select * from dbo.employee). 
No!  A stored procedure does not display anything anywhere.  The application which executes the procedures is responsible for the consumption of the resultset; it chooses what to do and what to display. 
Lastly, do not get into the lazy habit of using the asterisk in your tsql code.  That is not best practice.  Along with that, you should also get into the following best practice habits:
schema-qualify your objects (i.e., dbo.employee)
terminate every statement - it will eventually be required.

Similar Messages

  • How to create xml file from Oracle and sending the same xml file to an url

    How to create xml file from Oracle and sending the same xml file to an url

    SQL/XML (XMLElement, XMLForest, XMLAgg, etc) and UTL_HTTP.
    Whether that works for you with the version of Oracle you have, your requirements, and needs is another story. A little detail goes a long way.

  • How to collect form responses in adobe formscentral and at the same time receive form responses through email

    My client wants to have the form that I created in FormsCentral to be able to collect email responses. So to do this, I downloaded the form as PDF then imported it into Acrobat. I created a button in Acrobat (this will be for the email response part). I used this script for that function:
    // This is the form return email. It's hardcoded
    // so that the form is always returned to the same address.
    // Change address on your form to match the code below
    var cToAddr = "[email protected]"
    // First, get the client CC email address
    var cCCAddr = this.getField("ClientEmail").value;
    // Now get the beneficiary email only if it is filled out
    var cBenAddr = this.getField("BennyEmail").value;
    if(cBenAddr != "")
    cCCAddr += ";" + cBenAddr;
    // Set the subject and body text for the email message
    var cSubLine = "Form X-1 returned from client"
    var cBody = "Thank you for submitting your form.\n" + "Save the filled form attachment for your own records"
    // Send the entire PDF as a file attachment on an email
    this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});
    I got it from here: http://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address
    I'm still kinda not sure how it works but I'm getting the idea. Now what I'm having trouble with is, how do I make it so that the user will be required to click on the scripted button and at the same time, also click on the FormsCentral's generated submit button? Because as I see it, the user can click on the scripted button but they can just close out the form without submitting it to FormsCentral.
    Is there any way to make my idea work?
    Any help is very much appreciated!
    Thanks!

    I do not know or have time right now to look up NDP format.
    To write to NTFS from Mac, you need a driver.
    And to write to HFS from Windows also.
    I strongly recommend Paragon drivers for both.
    That way you can access anything from any platform.
    Paragon Software for Mac

  • Delete records in a table and at the same time print out for reference

    I am working on a req to delete some records from a table and at the same time, record/print the deleted records in the outstream (DBMS_OUTPUT.PUT_LINE)
    DECLARE
    v_rec_po hst_po%ROWTYPE;
    BEGIN
    DELETE FROM hst_po po
    WHERE abbrpoid = '&opportunity_code'
    AND updatedby = (SELECT employeeid
    FROM tes_employee
    WHERE name = &emp_name)
    AND audittimestamp BETWEEN TO_DATE ('&start_timestamp',
    'DD-MON-YYYY HH24:MI'
    AND TO_DATE ('&end_timestamp',
    'DD-MON-YYYY HH24:MI'
    END;
    I was thinking of using returning into and then using DBMS_output to pull out the delted records, but there will be multiple rows deleted fro this statements. I am stuck here..Can anyone help

    How about:
    SQL> create table t
      2  (x int)
      3  /
    Table created.
    SQL> insert into t
      2  select rownum
      3    from all_objects
      4   where rownum <= 10
      5  /
    10 rows created.
    SQL> declare
      2     cnt pls_integer;
      3  begin
      4     delete from t;
      5     cnt := sql%rowcount;
      6     dbms_output.put_line ('Removed: '||to_Char (cnt));
      7  end;
      8  /
    Removed: 10
    PL/SQL procedure successfully completed.Edited by: Alex Nuijten on Jun 4, 2009 8:58 AM

  • Nsert/Update and Add Column at the same Table and at the "same" Time

    Hello,
    I want Insert/Update and Add Column at the same Table and at the "same" Time but in different sessions.
    Example:
    At first the "insert/update" statement:
    Insert into TestTable (Testid,Value) values (1,5105);
    After that the "add" statement:
    Alter table TestTable add TestColumn number;
    - sadly now I get the message: ORA-00054: resource busy and acquire with NOWAIT specified
    "insert/update" statement:
    Insert into TestTable (Testid,Value) values (2,1135);
    After that the execute commit.
    I don't know when the first session set the commit statement so I want that the DB the "Alter Table..." statement execute if it's possible.
    If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.
    Thanks for ideas

    Well I want to walk in the rain without and umbrella and still stay dry, but it ain't gonna happen.
    You can't run a DDL statement against a table with transactions pending. Session 2 has to wait until session commits or rollbacks (or until the session is killed). That's just the way it is.
    This makes sense if you think about it. The data dictionary has to be consistent across all sessions. If session 2 was allowed to change the table structure whilst session 1 has a pending transaction then the database is in an inconsistent state. This is easier to see if you consider the reverse situation - the ALTER TABLE statement run by session 2 does a DROP COLUMN TESTID rather than adding a column: now what should happen to session 1's INSERT statement? You have retrospectively invalidated a statement that was perfectly legal when it was executed.
    If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.Fnord.
    Cheers, APC

  • Is there a way I can stream video from my 2012 AirMac to the Apple TV using airplay and at the same time stream the audio to an air speaker?

    Is there a way stream video from a 2012 MacBook Air to a TV using Apple TV and at the same time steam the audio to an air speaker. Also the same question but using an ipad

    You can try one thing. Follow these steps:
    1. On your Mac, turn on AirPlay Mirroring and connect it to the Apple TV, so audio and video will stream from the Apple TV.
    2. Turn off the sound of the TV where you have connected the Apple TV.
    3. Then, make sure that you have turned on the AirPlay speakers. Then, open System Preferences > Sound > Output, and choose the external speakers, so sound will stream from these external speakers.
    This should work correctly

  • How can I copy documents from a Sharepoint On Premises library to a Sharepoint Online library and at the same time preserving their metadata?

    How can I copy documents from a Sharepoint On Premises library to a Sharepoint Online library and at the same time preserving their metadata?
    I use the Open Explorer Windows to drag and drop the files, but the metadata are not copied. Thanks.

    To maintain the metadata you'll need to use one of the third party tools that does this kind of migration.  Metalogix has a product with a free trial that we have used before.  (Don't remember whether the free version maintains metadata or not).
     You can read about it here:
    http://www.metalogix.com/Products/Content-Matrix.aspx
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • Bluetooth seems like working since last week and at the same time I can't manage the Wi-Fi

    Bluetooth seems like working since last week and at the same time I can't manage the Wi-Fi. I have already restored.

    This entire thing is a hair over four months old, I don't think it should be acting up this much. Plus, this problem happens only once out of every 40 or 50 times I start this thing up. It's very infrequent, but it's there, and it just bothers me, I guess.
    That said, I would try reinstalling, but I wouldn't be able to tell if it'd worked unless the problem never cropped up again in a long, long time. Sadly I also don't have access to my OSX discs at the moment (I'm out of the country).

  • HT201412 I cannot activate my imessage and facetime and at the same time i cannot receive any notifications on my facebook.

    Hi.I noticed that my imessage and facetime is not working and at the same time i cannot receive any notifications on facebbok.

    Hi,
    To exclude software conflict, i recommend you to make a clean boot and then have a test.
    If this issue still persists, i suggest you re-built all COM ports through registry.
    Locate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter, delete ComDB key, reboot your computer.
    Andy Altmann
    TechNet Community Support

  • How to bind to a dataset and at the same time trim the text?

    Hi,
    I want to bind a listbox to a dataset, and the text value in the dataset is not always trimmed.
            Dim dsCity as dataset = GetListOfCity()
            ListBoxCity.DataSource = dsCity
            ListBoxCity.DataTextField = "CityName"
            ListBoxCity.DataValueField = "CityID"
            ListBoxCity.DataBind()
    I would like to ask if there is any handy way for me to bind to the dataset and at the same time, trim the text "CityName" when we are binding to it?
    Regards,
    Xavier

    Hi Xavier,
    Just as Uri Dimant said, we can use the Trim or Replace function in the textbox to trim leading or trailing spaces of any string. For example, we can use those functions as below:
    =Trim(Fields!FieldName.Value)
    =Replace(Fields!FieldName.Value, "  ", "")
    Besides, those two functions can also be done in the query with SQL.
    Reference:
    http://venkateswarlu.co.in/MSBI/ssrs/SSRS_Common_Functions__Text.aspx
    Hope this helps.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How do i get a still image to fade the same way and at the same time as a video?

    I have a video stacked on top of a still image. When i add a transition, the still turns to a black screen while the video fades in accordance to the transition. How do i get the still image to fade the same way and at the same time as the video?

    I do. I've applied it to both the  still image and the video. Say i used the lens flare transition. If i apply it to both the video and the still image, the video will dissolve in to the next frame, but the still image will go to a black screen and then jump to the next frame. Its almost as if i inserted a black frame instead of a transition, but only for 2 seconds. Below is kind of a peek what it looks like.

  • How do you import a .png file into the Final Cut Pro X and at the same time keep the file's original transparency settings?

    How do you import a .png file into the Final Cut Pro X and at the same time keep the file's original transparency settings?

    Go to the Info inspector for the still image and in settings select the alpha type.

  • PCI 6602:How can I use the digital lines of the board and in the same time to generate pulse train using a counter?

    Hello!
    My problem appeared when I tried to update my code from Traditional NI-DAQ Legacy to DAQmx.
    I am using 2 counters (counter 5 and counter 7)  from PCI-6602, to generate pulse train, and also the Digital I/O lines of the port 0 (the lines form 0 to 7). What I do in my application is that I am starting to generate the pulse train on the output of the 2 counters, and after that I am playing with the state of the digital lines.
    In traditional there was no problem using the counters and the digital lines in the same time, everything was going perfectly, but in DAQmx this is not possible.
    What happens: I start to generate pulse train on the output of the counters,  no errors encountered, but when I try to modify the state of one line of the digital port the generation of the pulse train is stopped. This is happening when I start the task associated to the digital port.
    My question is: it is possible to create a channel on the digital lines without altered the channels created for the counters?
    Another thing what I manage to see using the  "Measurement & Automation Explorer" and Test panels for PCI-6602, basically is the same thing, I generate pulse train on the output of the counter 7 and try to start a task on the digital line, but I get one error :
    "Error -200022 occurred at Test Panel
    Possible Reason(s):
    Measurements: Resource requested by this task has already been reserved by a different task.
    Device: Dev4
    Terminal: PFI8"
    Instead if I use the counter 0 or counter 1 to generate pulse train I don't encounter the same problem.
    Which resources are used by the counters 2 to 7 from the PCI-6602 board and the counters 0 and 1 do not use?
    Thank in advance for any replies!
    Ciprian
    Solved!
    Go to Solution.

    Hello Jordan, thank you for your reply.
    I am sorry but I can not see or run your example, I don't use LabView, I use Visual C++ for developing.
    Here is the code for generating the pulse train:
    GeneratePulseTrain(unsigned long ulCount1, unsigned long ulCount2)
        short nStatus = 0;
        nStatus = DAQmxCreateTask("",&m_taskHandle);
        nStatus = DAQmxCreateCOPulseChanTicks (m_taskHandle, "Dev4/count5", "", NULL, DAQmx_Val_Low, 0.0, ulCount1,ulCount2);
        if( bTriggerMode == true) // if hardware trigger is enabled
            nStatus = DAQmxSetTrigAttribute (m_taskHandle, DAQmx_ArmStartTrig_Type, DAQmx_Val_DigEdge);
            nStatus = DAQmxSetTrigAttribute (m_taskHandle, DAQmx_DigEdge_ArmStartTrig_Edge, DAQmx_Val_Rising);
            nStatus = DAQmxSetTrigAttribute (m_taskHandle, DAQmx_DigEdge_ArmStartTrig_Src,"Dev4/PFI17" );
        //set the internal timebase
        nStatus = DAQmxSetCOCtrTimebaseSrc(m_taskHandle,"Dev4/count5","20MHzTimeBase" );
        nStatus = DAQmxStartTask(m_taskHandle);
        return nStatus;
    And the code where I try to set the digital line:
    SetChannelState(short nState)
        short nStatus = 0;
        uInt8 wrtBuf0[1]={0};
        nStatus = DAQmxCreateTask("",&m_taskHandle);
        // Configure line as output 
        nStatus = DAQmxCreateDOChan (m_taskHandle, "Dev4/port0/line0", "", DAQmx_Val_ChanPerLine);
        nStatus = DAQmxStartTask(m_taskHandle);
        wrtBuf0[0] = nState;
        nStatus =DAQmxWriteDigitalLines (m_taskHandle, 1, 0, 0, DAQmx_Val_GroupByScanNumber , wrtBuf0, NULL, NULL);
        nStatus = DAQmxWaitUntilTaskDone(m_taskHandle,10);
        nStatus = DAQmxStopTask(m_taskHandle);
        nStatus = DAQmxClearTask(m_taskHandle);
        m_taskHandle = 0;
        return nStatus;      

  • Sql query-filter if 1 set of data exists and in the same time 2 set doesnt

    Hi guys,
    I need to write a query where I filter on certain data being present, but in the same time other data from the same table being not present.
    For example:
    ProceduresTable:
    Type 1
    Type 1
    Type 2
    Type 2
    Type 1
    MyTable:
    Name
    OtherFields
    JoiningTable (many to many)
    ProceduresTable_Key
    MyTable_Key
    I need to select all records from MyTable and Procedures for which there are procedures from Type 1 but there are no procedures from Type 2 in the same time.
    So far I've been only able to do that by using subqueries and I think there should be an easier way to do that.
    Here is what I have:
    Select * From MyTable, Procedures, JoiningTable Where JOINING_CONDITIONS AND Type = 1 AND NAME_SOME_COLUMN NOT IN (SELECT NAME_SOME_COLUMN FROM ... WHERE Type = 2 and inner.Name = outer.Name)
    Hope you understand my meta code. I have Oracle 9 db.
    Thanks a lot!

    Hi,
    Welcome to the forum!
    Whenever you have a question, it helps if you post a specific example. Include CREATE TABLE and INSERT statements for a little sample data, and also post the results you want from that data.
    if you can use commonly available tables (like those in the scott or hr schemas) to illustrate your proble, then you don't have to post the sample data; just the results.
    For example, I think you're asking something like this:
    "How can I find information about people in the sciott.emp table who are in a department that has at least one CLERK ( that is, a row with job='CLERK') but no SALESMAN? That is, I want these results:
    {code}
    ENAME DEPTNO JOB
    CLARK 10 MANAGER
    KING 10 PRESIDENT
    MILLER 10 CLERK
    JONES 20 MANAGER
    FORD 20 ANALYST
    ADAMS 20 CLERK
    SMITH 20 CLERK
    SCOTT 20 ANALYST
    {code}
    One way is to use CASE expressions instead of WHERE clauses to test for the criteria, then using the reults of the CASE expressions in the WHERE clause.
    For example:
    WITH     got_cnts     AS
         SELECT     ename,     deptno,     job
         ,     COUNT ( CASE
                             WHEN  job = 'CLERK'
                       THEN  1
                         END
                    ) OVER (PARTITION BY deptno)     AS clerk_cnt
         ,     COUNT ( CASE
                             WHEN  job = 'SALESMAN'
                       THEN  1
                         END
                    )     OVER (PARTITION BY deptno)     AS salesman_cnt
         FROM     scott.emp
    SELECT     ename,     deptno,     job
    FROM     got_cnts
    WHERE     clerk_cnt     > 0
    AND     salesman_cnt     = 0
    ;The problem here is that you can't always tell, by looking at any one row, if it should be included or not; in this case, you need to know something about the department as a whole. Analytic functions can look at the department as a whole, but analytic functions are computed after the WHERE clause is applied, so to use the results of the analytic functions in a WHERE clause, we need to do the analytics first, in a sub-query, and the WHERE clause later.
    Sometimes (as in the example above) analytic functions are useful; other times, aggregate functions are more appropriate, depending on the exact requirements.
    Edited by: Frank Kulash on Apr 12, 2010 9:00 AM

  • How can I sync over itunes and at the same time sync over icloud?

    Hello,
    I just recently updated my iTunes to the latest version and now run into the following challenge. With the "old" iTunes I was able to sync my Outlook calendar from my company computer over iTunes with my iPhone and my iPad. At the same time I was able to sync my private appointments on my iPhone over iCloud with my iPad. That way my appointments from my company computer appeared in a different color on my mobile devices as my private appointments and everything was fine.
    Now, after updating iTunes, I cannot sync my Outlook calendar from my company computer anymore - iTunes is just telling me I choose to sync my calendar over iCloud and leaves me no option anymore to sync "manually" in addition to the iCloud with iTunes.
    How can I solve the issue? Basically, how can I sync my company appointments with my iPhone without using iCloud on my company computer?

    Hi,
    I have the same issue and I can tell that it really *****. Now I have to manually copy cal items to my icloud calendar to have the business cal items on my iphone.  have looked into codetwo for icloud which is nice for notes, tasks and contacts but it only works for business cal items which I myself have created not for items for which I was invited. Contacted their support but I think it won't help.
    If you have any suggestions how to overcome this problem, I'd be glad if you posted your solution.
    Thx in advance
    iphone 5, iOS 6.0.1, icloud for windows 2.1, windows 7 64bit

Maybe you are looking for

  • How can I create a fillabe form

    I want to make a form fillable, in an E-Version. How do I do that?

  • Safari STILL crashing regularly

    I'm still having Safari crashing problems. It's getting ridiculous! It seems like the crash reports are always different. BTW, I've run the Apple hardware diagnostic on my system several times with not problems found. I've repaired permissions, delet

  • Does the end of the year upgrade policy also include just Photoshop?

    I understand CS3 and CS4 are eligible for upgrades to CS6 until the end of the year, but what about upgrading from PS4 to PS6? I normally upgrade to every version, but due to being layed up for 8 months with a knee injury money is extremely tight, so

  • Error when updating software

    Dear Apple Customer Care! crashes when updating IOS version 6.1.2, I'm using iphone 5. Pls, help me

  • Can't get "pianos and strings" on my 2nd computer. . .

    Weirdest thing. I use an instrument "pianos and strings" - I have purchased GB 08, the JamPack, and the Orchestral JamPack. I have no idea exactly where this particular instrument comes from. It plays fine on my Intel Mac. So I also installed on my l