-1

I have a below SQL query running in one of my project. I am struggling to understand the "as" concept here. In the result "user_key" and "user_all" are appearing as empty. Where as at the front end "user_all" is the combination of "rx.ord_by_userid" + "rx.ord_by_inst_id,"

SELECT  rx.rx_id, 
 rx.pt_visit_id, 
 rx.pt_id, 
 pt_visit.date_time_sch, 
 ' ' as print_dea_ind, 
 ' ' as phys_rx_label, 
 rx.ord_by_userid, 
 rx.ord_by_inst_id, 
 '                                                  ' as user_key, 
 pt_visit.visit_inst_id, 
 '                                                  ' as user_all, 
 ' ' as tp_agt_ind, 
 FROM rx LEFT OUTER JOIN tx_pln ON rx.tp_name = tx_pln.tp_name AND  rx.tp_vers_no = tx_pln.tp_vers_no, pt_visit 
WHERE ( pt_visit.pt_visit_id = rx.pt_visit_id ) and
( pt_visit.pt_id = rx.pt_id ) and
( ( rx.pt_id = :pt_id ) and
( rx.rx_id = :rx_id ) )  

Thanks.

user3022426
  • 49
  • 2
  • 8

2 Answers2

0

I think when they query database, they need two fields called "user_key" and "user_all" with empty value for some purpose. However, in the front end, they need to display column "user_all" with the combination of "rx.ord_by_userid" + "rx.ord_by_inst_id" because of business rule. The meaning of "AS" is just setting the alias of any field which is needed to have a new name. In this situation, new columns "user_key" and "user_all" are set with empty value.

0

AS just provides the field in the data set a name, or in SQL terms, an alias. In PB, this is usually done so that the DataWindow gives it a consistent, easy name. That is all that AS does.

The other part of your mystery is how these get populated with non-blank values. You were assuming this was done in the SQL with AS, but we can assure you that is not the case. Most likely, this value is being set in a script that fires in the client after the Retrieve() (if I were to bet, I'd bet a script on the DataWindow control, maybe RetrieveRow or RetrieveEnd).

Terry
  • 6,160
  • 17
  • 16