Index: trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 9592)
+++ trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 9593)
@@ -500,24 +500,37 @@
    query=" UPDATE "$step"Status "
    # add joins to the influenced tables
+   stepspecialjoin=""
    for influence in $influences
    do
-      # make sure that the right join is done 
-      #   in case the is a 'Join' given for the 
-      #   influenced step, this is added
-      # otherwise it is checked whether the executed step
-      #   itself needs a 'Join' (i.e. has different primaries)
-      #   if yes, the tables are joined with the primaries of the influenced step
-      #   else with the primaries of the executed step itself
-      stdjoin=`getjoin $influence`
-      if ! [ "$stdjoin" = "" ]
+      inflprims=( `getprimary $influence` )
+      # make sure that the correct joins are used
+      # in case the primaries of the step and the influence are 
+      #   the same, the tables are join with these primaries
+      # otherwise they are joined with the primaries of the influence
+      if [ "`echo ${inflprims[@]}`" == "`echo ${prims[@]}`" ]
       then 
-         query=$query" "$stdjoin" "
-      else
-         stdjoin2=`getjoin $step`
-         if [ "$stdjoin2" == "" ]
+         query=$query" LEFT JOIN "$influence"Status USING (${prims[@]}) "
+      else 
+         prims2=`getprimary $step | sed -e "s/\ //g"`
+         primstest=`echo ${inflprims[@]} | sed -e "s/\ //g" | sed -e "s/$prims2//g"`
+         if [ "$primstest" == "`echo ${inflprims[@]} | sed -e "s/\ //g"`" ]
          then
-            query=$query" LEFT JOIN "$influence"Status USING("`getprimary $influence`") "
+            if [ "$stepspecialjoin" == "" ]
+            then
+               stepspecialjoin=`getspecialjoin $step`
+               query=$query" "$stepspecialjoin" "
+            fi
+            query=$query" LEFT JOIN "$influence"Status USING (${inflprims[@]}) "
          else
-            query=$query" LEFT JOIN "$influence"Status USING("`getprimary $step`") "
+            infljoin=`getjoin $influence`
+            if [ "$infljoin" = "" ]
+            then
+               query=$query" LEFT JOIN "$influence"Status USING (${prims[@]}) "
+            else
+               query=$query" "$infljoin
+               # warning: this is a workaround
+               #  it has to be checked whether it works for all steps
+               stepspecialjoin="not empty"
+            fi
          fi
       fi
@@ -543,8 +556,8 @@
       s=0
    fi
-   query=$query" "`echo ${prims[0]} | sed -e 's/,//g'`"='${primaries[$s*${#prims[@]}]}'"
+   query=$query" "$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`"='${primaries[$s*${#prims[@]}]}'"
    for (( j=1 ; j < ${#prims[@]} ; j++ ))
    do
-      query=$query" AND "`echo ${prims[$j]} | sed -e 's/,//g'`"='${primaries[$s*${#prims[@]}+$j]}' "
+      query=$query" AND "$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`"='${primaries[$s*${#prims[@]}+$j]}' "
    done   
    # print query
