IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Static SQL and the Dynamic Sql query.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
arindambanerjee

New User


Joined: 30 Jun 2007
Posts: 39
Location: India

PostPosted: Tue Oct 20, 2009 12:19 am
Reply with quote

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
View user's profile Send private message
Steve Davies

New User


Joined: 15 Oct 2009
Posts: 32
Location: UK

PostPosted: Tue Oct 20, 2009 10:29 am
Reply with quote

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
View user's profile Send private message
ajeshrn

New User


Joined: 25 Mar 2009
Posts: 78
Location: India

PostPosted: Tue Oct 20, 2009 12:13 pm
Reply with quote

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
View user's profile Send private message
ajeshrn

New User


Joined: 25 Mar 2009
Posts: 78
Location: India

PostPosted: Tue Oct 20, 2009 12:33 pm
Reply with quote

Hi arinthambanerjee,

Please refer the below link too, you can get some more details on Static and Dynamic SQL.

www.ibmmainframes.com/viewtopic.php?t=4802
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
Search our Forums:

Back to Top