View previous topic :: View next topic
|
Author |
Message |
arindambanerjee
New User
Joined: 30 Jun 2007 Posts: 39 Location: India
|
|
|
|
Hi,
I am not very clear with Static and Dynamic SQL. Can someone please explain me the difference between the two and in what scenarios which is better. |
|
Back to top |
|
|
Steve Davies
New User
Joined: 15 Oct 2009 Posts: 32 Location: UK
|
|
|
|
Have you tried googling this - there's quite a lot of sites discussing this topic. IBM have some info on this too.
Click Here For IBM's pages. |
|
Back to top |
|
|
ajeshrn
New User
Joined: 25 Mar 2009 Posts: 78 Location: India
|
|
|
|
Hi arindambanerjee,
Dynamic SQL's are prepared during run time. The whole query will be embedded in working storage sections and will be prepared during run time.Please find the sample decaration as below for dynamic SQL
05 WS-Variable1 PIC X(100) VALUES
'Select * from Table1 Order by'
05 WS-Sort1 PIX S9(04) Usage Comp
05 WS-Variable2 PIC X(2) VALUES
','
05 WS-Sort2 PIX S9(04) Usage Comp
Same when we do using static SQL, we will be embedding the query between
EXEC SQL Select * from Table1 Order by 1,2 END-EXEC
As an example if you see the difference here, in the dynamic SQL, after order by I have kept two variables WS-Sort1 and WS-Sort2, values can be passed to this section ysung MOVE command.
In some case I need to sort the result using 3rd and 4rth column, so I will pass 3 to WS-Sort1 and 4 to WS-Sort2 through COBOL program.In case I want to sort by first and second column, then I MOVE 1 to WS-Sort1 and 2 to WS-Sort2.
But in case of static SQL, I will always be able to order by 1,2.In case we need to change the order, we need to change it in the query. |
|
Back to top |
|
|
ajeshrn
New User
Joined: 25 Mar 2009 Posts: 78 Location: India
|
|
Back to top |
|
|
|