How to write a store procedure under SQL Server 2008

Hi Folks,
Kindly help me step by step how to create a simple store procedure with help of sql server 2008 r2 for Crystal report.
I know how to work by using Universe but not SQL Server. Kindly help me how to hard code by using sql.
Thanks in adv.
Reddy

For the actual syntax for programming the stored proc, you'll need to work with someone (or a website) who knows T-SQL.
The cursor that gets returned from the stored proc must be an "in out" parameter for the stored proc.  For SQL Server I usually define a record type that includes the fields that will be returned and then return a set of records of that type.  Again, check with someone who is familiar with T-SQL for more information about how to do this.
-Dell

Similar Messages

  • How to Migrate Stored procedure on Sql server 2008 to Oracle Database

    Guys, I need help vey badly as I am new in this field.
    Problem is that, I have to migrate stored procedure on Sql server 2008 to oracle Oracle database:
    Whole scenario--
    1. Sql Server 2008 application on Windows server (source machine)
    2. I have to migrate 70 Stored Procedure
    3. To Oracle Database on Linux machine (Target machine)
    Any method (no problem)
    Please, help me or give me any reference as I don't know which keyword is differ in both database.
    Thanks in advance

    Hi,
      You could the free Oracle SQL*Developer to do this.
    There is information and a download link here -
    Oracle SQL Developer</title><meta name="Title" content="Oracle SQL Developer"><meta n…
    and information on using it for migrations here -
    http://www.oracle.com/technetwork/database/migration/index-084442.html
    You could use it in 2 ways -
    1. Go through a migration but just pull the stored procedure code from the file created after you generate the SQL from the SQL*Server database
    2. Use the scratch editor accessed from -
    - Tools - Migration - Scratch Editor
    and paste the SQL*Server stored procedure code into the window and it will convert it to Oracle code. The tool is very good but may have problems if you have very complicated procedures that use SQL*Server specific utilities.
    Regards,
    Mike

  • Improve the performance in stored procedure using sql server 2008 - esp where clause in very big table - Urgent

    Hi,
    I am looking for inputs in tuning stored procedure using sql server 2008. l am new to performance tuning in sql,plsql and oracle. currently facing issue in stored procedure - need to increase the performance by code optmization/filtering the records using where clause in larger table., the requirement is Stored procedure generate Audit Report which is accessed by approx. 10 Admin Users typically 2-3 times a day by each Admin users.
    It has got CTE ( common table expression ) which is referred 2  time within SP. This CTE is very big and fetches records from several tables without where clause. This causes several records to be fetched from DB and then needed processing. This stored procedure is running in pre prod server which has 6gb of memory and built on virtual server and the same proc ran good in prod server which has 64gb of ram with physical server (40sec). and the execution time in pre prod is 1min 9seconds which needs to be reduced upto 10secs or so will be the solution. and also the exec time differs from time to time. sometimes it is 50sec and sometimes 1min 9seconds..
    Pl provide what is the best option/practise to use where clause to filter the records and tool to be used to tune the procedure like execution plan, sql profiler?? I am using toad for sqlserver 5.7. Here I see execution plan tab available while running the SP. but when i run it throws an error. Pl help and provide inputs.
    Thanks,
    Viji

    You've asked a SQL Server question in an Oracle forum.  I'm expecting that this will get locked momentarily when a moderator drops by.
    Microsoft has its own forums for SQL Server, you'll have more luck over there.  When you do go there, however, you'll almost certainly get more help if you can pare down the problem (or at least better explain what your code is doing).  Very few people want to read hundreds of lines of code, guess what's it's supposed to do, guess what is slow, and then guess at how to improve things.  Posting query plans, the results of profiling, cutting out any code that is unnecessary to the performance problem, etc. will get you much better answers.
    Justin

  • How to convert rows to columns in sql server 2008

    How to convert rows to columns in sql server 2008 using the GROUP BY function? (only one query allowed)

    Lookup the Pivot transformation. From BOL:
    The Pivot transformation makes a normalized data set into a less normalized
    but more compact version by pivoting the input data on a column value. For
    example, a normalized Orders data set that lists customer name, product, and quantity purchased typically has multiple rows for any customer who purchased multiple products, with each row for that customer showing order
    details for a different product. By pivoting the data set on the product column, the Pivot transformation can output a data set with a
    single row per customer. That single row lists all the purchases by the customer, with the product names shown as column names, and the quantity shown as a value in the product column. Because not every customer purchases every product, many columns may contain
    null values.
    When a dataset is pivoted, input columns perform different roles in the pivoting process. A column can participate in the following ways:
    The column is passed through unchanged to the output. Because many input rows
    can result only in one output row, the transformation copies only the first
    input value for the column.
    The column acts as the key or part of the key that identifies a set of
    records.
    The column defines the pivot. The values in this column are associated with
    columns in the pivoted dataset.
    The column contains values that are placed in the columns that the pivot
    creates.
    Paul

  • How to connect from Oracle 11g to SQL Server 2008 R2

    Hi,
    Is it possible to connect from Oracle 11g on AIX to SQL Server 2008 R2? If so, what is the preferred method?
    SQL Server has the original table. From Oracle 11g, we want to access data which is in SQL Server real time.
    Thank You
    Sarayu

    Hi,
    Have a look at these Oracle notes for the full information on the gateways -
    Master Note for Oracle Gateway Products (Doc ID 1083703.1)
    Functional Differences Between DG4ODBC and Specific Database Gateways (Doc ID 252364.1)
    Gateway and Generic Connectivity Licensing Considerations (Doc ID 232482.1)
    How to Setup DG4MSQL (Oracle Database Gateway for MS SQL Server) 64bit Unix OS (Linux, Solaris, AIX,HP-UX) (Doc ID 562509.1)
    How to Configure DG4ODBC on 64bit Unix OS (Linux, Solaris, AIX, HP-UX Itanium) to Connect to Non-Oracle Databases Post Install (Doc ID 561033.1)
    The Database Gateway for SQL*Server (DG4MSQL) needs a separate license but the Database Gateway for ODBC (DG4ODBC) is included in your RDBMS license. You only need to provide the third party ODBC driver needed by DG4ODBC.
    Regards,
    Mike

  • How can this encoding be saved in SQL Server 2008

    hi all,
    We are using Sql Server 2008, it has this collation set "SQL_Latin1_General_CP1_CI_AS". Please have a look at this file:
    https://drive.google.com/file/d/0BxWAyvJA9ZjCdkFNN3BXZUw3dEE/view?pli=1
    its a text file in text format (ascii test data format aka ATDF). Its coming from French vendor and it contains some French words. We have to parse this and upload data to sql server. We do that all the time except this file is not working. It just disturbs
    the way sql server is saving data for us, and upon showing this saved data on application UI, the correct letters don't display. The upload happens via the Bulk Insert command. Please guide as to where to start. Also please let me know exactly what this format
    is called, do we call it just unicodes, or some utf formats. I'm really ignorant when it comes to unicode. Thanks a lot!
    ..ab
    Ab

    Hi
    Please use Unicode data types on the SQL Server side. Please see the following document:
    http://msdn.microsoft.com/en-us/library/ms187828(v=SQL.105).aspx 
    Thanks
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • How to install BIDS to existing installed sql server 2008 express?

    hello...
    i have sql server 2008 express installed on machine. and i want to install business intellegence development studio 2008 for this installed version. i don't want to destroy current databases running on this version.
    plz help me

    Hello,
    To get BIDS you have to use the "Microsoft® SQL Server® 2008 Express with Advanced Services" installer, during Installation you can select the Features you want to install; here you
    can select only BIDS.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Call Store Procedure in SQL Server

    How can I call an Oracle Store Procedure in a SQL Server procedure?

    Make sure you're calling the stored procedure with the same parameters at the same database. If that's not the case then send the procedure body and how you are calling it from code and DB .
    "If there's nothing wrong with me, maybe there's something wrong with the universe!"

  • Passing a table-field value in Crystal to a Store Procedure in SQL Server

    I have been checking all over the interenet via searches and although some seem to come close to this, its still not what I want.
    Essentially I need to pass value from Table-Field record (for each record read/selected) via a paramete to a Stored Procedure(SP) in SQL Server 2205/2008.  I do NOT want to be prompted for a value for this parameter each time the report is run, simple pass the value in which will be used along with other select criteria to bring back one value for the report to use in a calcuation per record.
    The value of the parameter is a date, but I understand it would be better to pass it in as a varchar(8) - 'YYYYMMDD' - and then reconvert it inside the SP, as follows:
    In Crystal Reports 2008 SP3, I have a formula defined as,
    trans_date = ToText ({F1ARS_STMT_WS_TRAN.TRANS_DATEI}, 'YYYYMMDD')
    and essential just want to pass this to the SP below ... i.e. trans_date  ---> @strTransDate
    I then link the key fields [EXCH_RATE_TABLE_NAME] and [TRANS_CCY_CODE] to other tables in the Database Expert, and put [EXCH_RATE_AMT] on the report and use it to calculate what I want.
    This works fine when the prompt comes up and I put in a proper date, but I don't what it to prompt, but simple pass the F1ARS_STMT_WS_TRAN.TRANS_DATEI in via the fornula/parameter and let teh SQL do the rest for each record selected..
    CREATE PROCEDURE [dbo].sp_GET_EXCH_RATE_AMT (@strTransDate varchar(8))     --use format 'YYYYMMDD' to represent the date as a string.
         -- Add the parameters for the stored procedure here
         -- @TransDate datetime = now
    AS
           declare @TransDate datetime
         set @TransDate = CONVERT(DATETIME, @strTransDate, 112)
    BEGIN
         -- SET NOCOUNT ON added to prevent extra result sets from
         -- interfering with SELECT statements.
         SET NOCOUNT ON;
        -- Insert statements for procedure here
    SELECT [EXCH_RATE_TABLE_NAME], [TRANS_CCY_CODE], [EXCH_RATE_AMT]
    FROM [F1CCY_EXCH_RATE]
    WHERE [MAJOR_CCY_CODE] = 'BBD'
    AND   [START_DATEI] =
         SELECT MAX([START_DATEI])
         FROM [F1CCY_EXCH_RATE]
         WHERE [MAJOR_CCY_CODE] = 'BBD'
         AND   [START_DATEI] <= @TransDate
    END
    GO
    GRANT EXECUTE ON sp_GET_EXCH_RATE_AMT TO PUBLIC
    GO
    Thanks for any help.  Can't tell the headache this has caused my both literally and figuratively.

    Hello,
    I moved your post to the Report Design forum. Lots of SQL help in here...
    I believe the problem is due to you using a Parameterized Stored Procedure. The first thing CR has to do is connect to your DB source which requires the date parameter before it can run the query to add the date filter, it's the SP that is prompting for the parameter. Therefore the report has not run so it can't get the field value from the report until you fill in the info for the SP. Catch 22 problem.... Which came first, the Chicken or the Parameter....
    The report will work as you have noted but I don't know of anyway to refresh unless parameter is filled in again....
    Jason has a lot of great solutions when it comes to these dilemmas, Possibly using a Command Object may help but I believe you will still run into the same issue....
    Only way I can think of is to not use a parameter in the SP and let CR do the filtering client side. Of course this means all data is coming back to the client PC as you are likely trying to find a work around for.
    Thank you
    Don

  • How to update the identity_column value in sql server 2008

    Hi Team,
    I have identity column based table. In the table i use insert the name as per the requirement and for ID i use to set the identity now i need to update the particular row id.
    when i use to trying i'm getting the below error.
    Msg 8102, Level 16, State 1, Line 4
    Cannot update identity column 'CategoryID'.
    Kindly help me out regarding this.
    Thanks & Regards,
    Ramesh R

    You cannot update an IDENTITY column. You need to move the data into another table make  the changes over there  and insert the back the data into original table.
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to debug a stored procedure in sql server 2012 ?

    whenever I do a change to a stored procedure and then run the alter proc again
    after that I place a break point on the exec stored procedure and try to step into the code 
    SQL management studio starts stepping into an older version of the stored procedure (i.e it does not feel the changes I made )
    How to get it to step through the latest version ? 

    Hi,
    Not sure what the exact problem is.. Refer the link below..
    http://stackoverflow.com/questions/8961600/debugging-does-not-show-current-stored-procedure-version
    Regards,
    Brindha.

  • How to hide not all but a specific database on a SQL Server 2008 R2 instance?

    Hello everyone,
          I need help from all the SQL Server database security experts out there. Any solution/help or work-around will be really appreciated. Here is the scenario; our client is using our application which is a windows forms application
    having in backend as a database under SQL Server 2008 R2 instance. We have successfully installed the SQL Server software with mixed mode authentication on client side, our application is running smoothly and everything is working fine. Our database on which
    application is running is quite intuitive, in the sense, all employees information is stored in EmployeeMaster and all departments information is stored in DepartmentMaster and so on. It consists of more than 500 such tables, stored-procedures and views. We
    have encrypted stored-procedures and views, problem is only with tables.
    We don't want table structure to be visible to anybody in SSMS (or tables must be hidden from all the users) but at the same time the tables should be accessible from the application. And we don't want to go with the option of encrypting
    the tables data and changing the names of all the tables to T001,T002..etc. as that is not feasible. And one last thing, we cannot restrict 'sa' login's password, it has to be shared with the client.
    Regards,
    Sumit R. Santani

    Also, will you please enlighten me more on what you said as "couple of choices" if I want to lock out plain users only?
    Assuming that you are selling a solution to a client, it's more an issue for your client's IT department, that do want their users to connect with Excel or SSMS.
    Anyway, I have a brief overview here:
    http://www.sommarskog.se/grantperm.html#Othermethods
    Again my question on that is how much reliable will be that license agreement?
    That depends on the lawyer you engage to write the license agreement.
    How would I come to know what they are doing with our database?
    Trust. Trust is extremely important. It is very difficult to make business if you don't trust people.
    That said, there are basically two reasons you want to hide the application from the client. One is protecting intellectual property. To this end, I know of nothing else than trust. And maybe after all, your application is not so fantastic that it is worth
    stealing anyway.
    The other reason is that you don't want the client to change it, and then open a free support case when he has messed up. To this end there are some technical approaches you can take to detect such tampering. For instance, you can sign all stored procedures
    with certificates using ADD SIGNATURE WITH SIGNED BLOB, and then ship only the public key of the certificate. This permits SQL Server to verify the signature, but the client cannot change the signature and sign it with that certificate, because the private
    key is not available to them.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Creation of System Stored Procedure in SQL Server 2012 & SQL Server 2012 R2.

    Hi all,
    I am stuck at a point I am looking for a system stored procedure named 'sp_dboption' in SQL Server 2012  & R2 but could not find.
    Searched for it on the net and found that, this stored procedure 'sp_dboption' is now obsolete. So I tried to copy the content of 'sp_dboption' stored procedure from SQL Server 2008 R2 and create new system stored procedure with this name 'sp_dboption' in
    SQL Server 2012 but was unable to create the system stored procedure.
    Can you guys please tell me how to create system stored procedure in SQL Server 2012 & SQL Server 2012 R2. The reason of why I want to achieve this is because I have used 'sp_dboption' system stored procedure  in my application to create a database.
    As 'sp_dbotion' stored procedure is present in SQL Server 2008 R2 I am able to create the database in SQL server 2008 R2 but not in SQL server 2012.
    Can you please guide me how to create system stored procedure. I am out of luck.
    Please assist me, thanks & looking for help at the earliest. Hope someone will come to the fore and help me.

    Hi Vishwajeet,
    If you tried to create any object in the sys schema, you will get the error below.
    The specified schema name "sys" either does not exist or you do not have permission to use it.
    So I am afraid creating any object in sys schema is not supported by SQL Server. Here is a similar link for your reference.
    How to create table in SYS schema in SQL Server?
    Though sp_dboption is not in SQL Server 2012, does creating a user-defined one with the same content in 2008 make any difference in your business? You just need to specify the fully qualified name dbname.dbo.sp_dboption.
    If you are still interested in creating a system sp_dboption, you can register it with the
    sp_ms_marksystemobject.
    See
    Creating Your Own SQL Server System Stored Procedures.
    Eric Zhang
    TechNet Community Support

  • How to configure Sql Server 2008 R2 for debugging without disabling Windows Firewall?

    When I try to debug a procedure in Sql Server 2008 R2 I get a dialog box telling me to unblock some ports.
    >>
    The Windows Firewall on this machine is currently blocking remote debugging.  Remote debugging requiers that the debugger be allowed to receive informatino from the network.  Remote debugging also requires DCOM (TCP Port 135) and IPSEC (UDP 4500
    / UDP 500) be unblocked.
    <<
    I went to the Windows Firewall and added some new Inbound rules for each of the specified ports (in the images below.  But after this and rebooting entire computer -- I still get this dialog box when I want to go into debug mode from SSMS.  I can
    actually kind of debug standalone code in the SSMS window if I cancel the dialog box.  But I can't debug an actual stored procedure -- which is what I need to do.  I also noticed that my server has an IP address instead of LocalHost.  This is
    not a public Server -- it's my private development machine which is on a peer to peer network (with one other workstation), but I don't need that workstation to be able to access this server..  Would localholst make a difference for debugging?  How
    should I configure the sql server?  The firewall?
    Rich P

    Use PRINT and SELECT for debugging. That's what I do. I used to play with the debugger in SQL 2000 and older days, but I realised that I spent more time on getting it to work that I gained from using it.
    I thought about that.  I guess that IS the way to go.  Very well.  Thank you for the suggestion.   Although, when the debugger does work in the regular window (not a stored proc because it doesn't work there) the debugger IS nice. 
    For debugging my proc I am thinking I will insert param vals into a test collection table for now.  One obscure error I am getting with a particular proc -- in a When loop on one parameter I get the "value will be truncated" error -- but everything
    is set to accept 1000 characters and none of the source data even comes close to 1000 characters.  I have isolated at what point the error occurs and which section of data where the error is occurring but I have not isolated the cause of the error. 
    I cannot reproduce the error when I run the procedure by hand in a regular query window with the exact same code.  The error only occurs when the code is run in the stored proc.
    Rich P

  • Debugging stored procedure in SQL Server 2012

    Hi,
    Please I need your help.
    I used to debug stored procedures in SQL server 2008, 2008 R2. I'm debugging the stored procedure using SQL Server management studio. I just create a break point then I click on the debug button
    and start debugging without any problems.
    I'm talking about my local machine which I have administrator privileges on the machine. My account in the administrators group and I'm assigned in the sysadmin role in SQL server but I couldn't
    debug the stored procedure. When I create a break point and try to debug the stored procedure I'm getting a popup screen saying "To continue debugging, the firewall needs to be configured. Configuring the firewall requires privileges."
    I tried to figure out the issue but unfortunately until now I'm not able to resolve it.
    Thanks. 

    The problem resolved with help of Microsoft support but it was really strange situation.
    First, the following is my environment.
    OS is Windows 8 Pro
    SQL Server 2012
    I did try everything firewall, Anti-Virus and other thing as well. I usually type (local) on the server name TextBox. I did close my Anti-Virus program, turn off windows firewall and run SQL server as administrator but I’m still
    unable to debug.
    I just do one thing and one thing only, changed the (local) on the server name TextBox to the actual server name and everything work fine. I did try that with everything close/open my Anti-Virus program, turn
    off/one windows firewall and still work fine, and I was able to debug any T-SQL in SQL server 2012 but run it as administrator.
    Anyway, I’m happy to back on the road again.
    Thank you every single one of you who try his best to help.
    Cheers.

Maybe you are looking for