473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How can I convert this sql query to a stored procedure?

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT  broker,
  2. COUNT(case when cntsze=20 then cntsze end) as '20',
  3. COUNT(case when cntsze=40 then cntsze end) as '40',
  4. COUNT(case when cntsze=45 then cntsze end) as '45' 
  5. FROM CYMgps
  6. WHERE ( sysdte BETWEEN '2012-11-01 00:00:00' and '2012-11-30 23:59:59')
  7. GROUP BY  broker
  8. ORDER BY broker asc
Jan 11 '13 #1

✓ answered by Uncle Dickie

Start it with:

Expand|Select|Wrap|Line Numbers
  1. USE <database>
  2. GO
  3. CREATE PROCEDURE <procedure_name> AS
  4.  
  5. -- your query here
If you need to edit it in future:
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE <procedure_name> AS

10 10491
Start it with:

Expand|Select|Wrap|Line Numbers
  1. USE <database>
  2. GO
  3. CREATE PROCEDURE <procedure_name> AS
  4.  
  5. -- your query here
If you need to edit it in future:
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE <procedure_name> AS
Jan 11 '13 #2
hi akocjello,
create the procedure like below.
create procedure procedurename
as
begin
//write the query u want to perform
// e.g select * from tablename
end


then

execute procedure procedurename
Jan 11 '13 #3
NeoPa
32,556 Expert Mod 16PB
When you choose to create or add a new Stored Procedure all these heading and trailing bits are inserted for you. You simply need to fill in the name etc. and the SQL and save it. It's hard to imagine why you would need to ask such a question unless you hadn't even looked at it for yourself first.
Jan 11 '13 #4
how to pass the immediate values to load event
Jan 12 '13 #5
NeoPa
32,556 Expert Mod 16PB
What do you mean by "load event"? I know of no such concept.

I can guess you mean literal when you say "immediate", but I'm still left with no idea what your question means.
Jan 12 '13 #6
thanks for the reply

NeoPa i looked it for my self but when i tried to do it i always encountered an error... but now it works :)
can i ask another question?
Jan 13 '13 #7
NeoPa
32,556 Expert Mod 16PB
You certainly may ask a new question, but just as certainly not in this thread.

Each question must be asked in a separate thread of course, but the question you want to ask should also be asked in a different forum. You won't find that many VB.NET experts that frequent this (SQL) forum ;-)
Jan 14 '13 #8
Sorry NeoPa im new in this forum and i dont know that... thanks for telling me

sorry again :)
Jan 14 '13 #9
NeoPa
32,556 Expert Mod 16PB
No need to worry at this stage. I can see you are new and nothing you've done yet has been a problem.
Jan 14 '13 #10
thank you for all the reply :)
i made it. now my program is 90% done :)


thanks again :)
Jan 16 '13 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Krzysztof Rozmus | last post by:
Hi, I have stored procedure (MS SQL Server 2000) which operates on around 600 000 rows (SELECT, UPDATE, INSERT) and executes in 5 minutes, when I put it in SQL transaction it slows down to...
1
by: Matt | last post by:
I would like to convert a couple informix stored procedures to SQL Server stored procedures. I have no idea how to accomplish this. Here is an example of one of the procedures I need to convert. ...
3
by: John | last post by:
Anyone have any tips on how to "convert" queries created in the Query By Design to SQL for VBA in Access? I particularly have difficulties with all of the quotation marks involved with parameters...
1
by: Dean L. Howen | last post by:
I try to get the result of the procedure in C#, it seems too many results that a procedure can return. Example: ---------------------------------------------------------- USE Northwind GO ...
2
by: Chris | last post by:
hi, I have created my own dll file that I would like to use in sql 2000 as an extended stored procedure. I have checked the dll is written correctly (I can use it in other application). The dll...
8
by: Ivan | last post by:
Hi I am new in DB2, and I have some problems when I try run stored procedures, and others statements. I made one stored procedure very simple, but this show different messages. I have followed...
1
by: meendar | last post by:
Hi, Please see the below procedure. create procedure a1 as begin
5
by: bobh | last post by:
Hi All, I have this query which updates a field based on the result of an IIF statement. The table is on SQLServer and I'm linked to it and it has many records and will take Access a very long...
1
by: Michel Walsh | last post by:
In the same spirit, but more LINQ related, you can also use ExecuteQuery: var query = dataContext.ExecuteQuery<className>( @"SELECT ... WHERE ... AND... OR... "); where className is...
1
by: osman7king | last post by:
hello all... I'm trying to convert the query which uses outer join statment from Oracle to PostgreSQL but I have some problems with this query may some one help me for this problem? SELECT ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.