CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

12Next
Return to list New
View: 3025|Reply: 21

Store Procedure dan Dynamic SQL

[Copy link]
Post time 9-11-2007 09:41 AM | Show all posts |Read mode
Login nak minta pendapat daripada kengkawan, cam ner buat store procedure dan dynamic sql berdasarkan cerita login dibawah ni:

~ Login nak create satu page yang memaparkan jumlah capaian ke modul-modul utama laman web. Login gunakan SQL utk query data dari database, dan paparkan di web menggunakan asp.
~ Login dapatkan data2 berkaitan daripada table logTaracking
~ Terdapat lebih kurang 10 modul yang login nak kira
~ Apa yang login buat sekarang adalah membuat query satu demi satu seperti berikut :


  1. strSQL2 = "SELECT COUNT(*) AS BAch FROM logTracking WHERE Type LIKE '%Dynamic%' AND EventID LIKE '%view%' AND Detail1 LIKE '%Achievement%' AND MONTH(DateRec)= '"&Request.Form("sltBulan")&"' AND YEAR(DateRec)= '"& request.form("sltTahun")&"'"
  2. set rs02 = con.execute (strSQL2)
Copy the Code

  1. strSQL3 = "SELECT COUNT(*) AS BCV FROM logTracking WHERE Type LIKE '%Dynamic%' AND EventID LIKE '%view%' AND Detail1 LIKE '%CV%' AND MONTH(DateRec)= '"&Request.Form("sltBulan")&"' AND YEAR(DateRec)= '"& request.form("sltTahun")&"'"
  2. set rs03 = con.execute (strSQL3)
Copy the Code


~ masalah yang login hadapi dengan cara ni adalah, login terpaksa buka 10 connection (10 query yang sama) untuk 10 modul, dan ini menyebabkan apabila dipublish ke internet, masa yang diambil untuk load data terlalu lambat iaitu 14 - 15 saat.

~ Pendekatan yang login rasa paling sesuai untuk menggantikan query ini kepada dynamic

~ syarat2 (condition) query login :
1. Kira bilangan modul (contoh modul CV, News)
2. Column Type hendaklah = Dynamic
3. EventID = View
4. Detail1 mengandungi nama/maklumat modul i.e modul CV, News, Services dan sebagainya.

harap ada dikalangan forumer boleh bantu
Reply

Use magic Report


ADVERTISEMENT


Post time 9-11-2007 10:04 AM | Show all posts

Reply #1 Login_ID's post

Memang kalau lebih 2-3 query yg sama, perlu create stored procedure, performance wise lagi cepat. sample nak create stored procedure utk oracle:-

http://www.ics.com/support/docs/dx/1.5/tut6.html
Reply

Use magic Report

 Author| Post time 9-11-2007 03:51 PM | Show all posts

Reply #2 syasya99's post

tq syasya

ada tak rujukan stored procedure utk sql

login tak familiar dgn oracle (tak pnah pakai pun)
Reply

Use magic Report

Post time 10-11-2007 03:35 AM | Show all posts

Reply #3 Login_ID's post

pakai sqlserver apa?

2000 ke 2005 ke express?
Reply

Use magic Report

Post time 10-11-2007 12:08 PM | Show all posts

Reply #1 Login_ID's post

kalau tengok kepada query tu mmg database kena buat table scan,yg semestinya akan hurt performance,either pakai dynamic sql atau stored procedure pun.Kalau bilangan row 100 mungkin tak rasa,tapi bila row dah jadi 100,000 akan terasa ke-slow-an query tersebut.
Reply

Use magic Report

Post time 11-11-2007 06:36 PM | Show all posts
huhh advance nihh!!!.. tp kalo buat cara lain xlehh ker... mcm buat kt code behind dia ker... buat ah select case utk open sql statement dier.. pastuhh kalo connection tuh  xleh ker kalo constant kan jer.. (eh bleh ker) kasi public nyer.. xpun guna session dr 1st login...

hemm tp ko diwajibkan/mesti guna storedprocedure/dynamic tuh ker.. xleh guna cara lain... apsal susah2?? dah kalo database makin besar.. hemm...

heheh menjawab soalan ke aku nih...
Reply

Use magic Report

Follow Us
Post time 11-11-2007 06:36 PM | Show all posts
ko guna microsoft sql server 2005 ker... ...

[ Last edited by  naikAntena at 11-11-2007 06:39 PM ]
Reply

Use magic Report

 Author| Post time 12-11-2007 08:34 AM | Show all posts

Reply #4 stingbeh's post

sql server 2000
Reply

Use magic Report


ADVERTISEMENT


 Author| Post time 12-11-2007 08:41 AM | Show all posts

Reply #6 naikAntena's post

buat ah select case utk open sql statement dier


TQ atas idea ini.

Setau login, bila kita pakai dynamic sql, kita memang hanya akan buka satu connection sahaja.
Kita boleh buat condition untuk mendapatkan kiraan untuk semua modul tersebut samada menggunakan select case, do while, atau if..then..else,
Masalahnya sekarang, login masih kurang faham dan tidak tahu macamana utk declare, seterusnya passing nilai parameter dalam dynamic sql
sedang belajar, dan sedang try..
Reply

Use magic Report

 Author| Post time 12-11-2007 08:41 AM | Show all posts

Reply #6 naikAntena's post

buat ah select case utk open sql statement dier


TQ atas idea ini.

Setau login, bila kita pakai dynamic sql, kita memang hanya akan buka satu connection sahaja.
Kita boleh buat condition untuk mendapatkan kiraan untuk semua modul tersebut samada menggunakan select case, do while, atau if..then..else,
Masalahnya sekarang, login masih kurang faham dan tidak tahu macamana utk declare, seterusnya passing nilai parameter dalam dynamic sql
sedang belajar, dan sedang try..
Reply

Use magic Report

Post time 12-11-2007 02:57 PM | Show all posts
add stored procedure tu kat ko punya database.... ko boleh tengok kat SQL enterprise manager, under database name ko ada stored procedure ...ko create baru ....lepas tu...ko boleh tambah SQL statement ko.. dah siap ...check syntax..

procedure nie....ko boleh panggil dalam sql statement.
Reply

Use magic Report

Post time 13-11-2007 12:21 AM | Show all posts

Reply #1 Login_ID's post

Kenapa tak lambak dalam satu SQL query? Guna aggregate and GROUP BY function. Cth:

SELECT <modul>, Count(*) as Total_Hits
FROM <nama table>
WHERE <criteria>
GROUP BY <modul>

That way you will only run one SQL query but have result for all the modules.
Reply

Use magic Report

Post time 13-11-2007 04:29 PM | Show all posts

Reply #9 Login_ID's post

maksud saya buat select case dlm code behind.. bkn in store procedure/dynamic.. tuh...

(selalunya smpai part store procedure nihh org lain yg buat kan.. saya x tahu sgt punnn!!!)....

[ Last edited by  naikAntena at 13-11-2007 04:44 PM ]
Reply

Use magic Report

Post time 20-11-2007 02:45 PM | Show all posts
strSQL2 = "SELECT Detail1,(select count() as  bil from logTracking WHERE Type LIKE '%Dynamic%' AND EventID LIKE '%view%' AND Detail1 LIKE '%Detail1%' AND MONTH(DateRec)= '"&Request.Form("sltBulan")&"' AND YEAR(DateRec)= '"& request.form("sltTahun")&"'"
set rs02 = con.execute (strSQL2)
)
FROM logTracking
///////////////////////////////

nih aku panggil sql select dalam select... mule2 ko select kolum detail sahaje,then select count bagi setiap detail...  dalam satu sql select ade lagi satu sql select... makne nye ko select due kolum la..yg pertame detail.. yang kedue count bagi setiap detail tu.. paham tak..  he he.. tp aku paham la maksud sql ko tuh..takyah sampai nak buat 10 sql.. klu 100 jenis detail takkan nak buat 100 sql
Reply

Use magic Report

Post time 20-11-2007 02:46 PM | Show all posts
banyaknye posting

[ Last edited by  alamak80 at 20-11-2007 02:50 PM ]
Reply

Use magic Report

Post time 20-11-2007 02:46 PM | Show all posts
strSQL2 = "SELECT Detail1,(select count() as  bil from logTracking WHERE Type LIKE '%Dynamic%' AND EventID LIKE '%view%' AND Detail1 LIKE '%Detail1%' AND MONTH(DateRec)= '"&Request.Form("sltBulan")&"' AND YEAR(DateRec)= '"& request.form("sltTahun")&"'"
set rs02 = con.execute (strSQL2)
)
FROM logTracking
///////////////////////////////

nih aku panggil sql select dalam select... mule2 ko select kolum detail sahaje,then select count bagi setiap detail...  dalam satu sql select ade lagi satu sql select... makne nye ko select due kolum la..yg pertame detail.. yang kedue count bagi setiap detail tu.. paham tak..  he he.. tp aku paham la maksud sql ko tuh..takyah sampai nak buat 10 sql.. klu 100 jenis detail takkan nak buat 100 sql
Reply

Use magic Report


ADVERTISEMENT


Post time 20-11-2007 02:55 PM | Show all posts
SELECT <modul> as mod1 ,( select  Count(*) as Total_Hits  from < logTracking> WHERE <modul> = mod1)
FROM <logTracking>
WHERE <criteria>

output = Achievemen       100
              CV                    200
Reply

Use magic Report

Post time 21-11-2007 01:23 PM | Show all posts
thread ni cukup utk membuatkan aku pening...
Reply

Use magic Report

Post time 21-11-2007 01:30 PM | Show all posts
Originally posted by shahnazz at 13-11-2007 12:21 AM
Kenapa tak lambak dalam satu SQL query? Guna aggregate and GROUP BY function. Cth:

SELECT , Count(*) as Total_Hits
FROM
WHERE
GROUP BY

That way you will only run one SQL query but hav ...


betul tu...simple and elegant...

SELECT Detail1,COUNT(*)
FROM logTracking
WHERE Type LIKE '%Dynamic%'
AND EventID LIKE '%view%'  
AND MONTH(DateRec)= <param>
AND YEAR(DateRec)= <param>
GROUP BY Detail1
Reply

Use magic Report

Post time 21-11-2007 03:47 PM | Show all posts
dah 2 minggu nih.. login apa perkembangan .. cam nerk ko setel problum tuhh.. aku pun nk tahu jgkkk....
Reply

Use magic Report

12Next
Return to list New
You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

5-1-2025 08:55 AM GMT+8 , Processed in 0.062435 second(s), 33 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list