on 07-25-2014 11:52 AM
Friends,
PB 7.0
DB: sql server 2008
string mid;
mid=get_user();
messagebox("test",mid);
above message box is showing the value of mid correctly...
but when i pass this variable to the below query i am not getting the value.
where i am making mistake....? please check the red colored text and correct me...my issue is only with the variable not with the query...
s4 = 'insert into student select RollNumber, FirstName,CSubjectCode, ' &
+ 'Internal_1,Mentor ' &
+ 'FROM Marks_Final ' &
+ 'WHERE (Internal_1 is not null) and ' &
+ '(feeactive="Y") and mentor="+mid+" ' &
+ 'GROUP BY RollNumber'
thanks
Your mistake is the logic you use to construct the string used as the query. As the others have suggested, you should visually inspect the string after building it to see the problem. You have embedded the word "mid" into your query and not the value contained in the variable named mid (which isn't particularly well-named since "mid" is function name). In addition, you should not be using double quotes to delimit string in tsql since that will work ONLY if you have a specific and non-default setting. The code below demonstrates the issue more clearly.
string ls_temp, ls_temp2
string mid
mid = "Jones"
ls_temp = 'WHERE (Internal_1 is not null) and ' &
+ '(feeactive="Y") and mentor="+mid+" ' &
+ 'GROUP BY RollNumber'
ls_temp2 = "WHERE (Internal_1 is not null) and (feeactive='Y') and mentor= '" + &
mid + "' GROUP BY RollNumber"
Messagebox ("test", "#1=" + ls_temp + "~r~n~r~n#2=" + ls_temp2)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's no aggregate function in the select, I'm wondering if the GROUP BY is necessary. Try to precede the double quote with a tilde and see if it makes a difference. You also missed the single quote before the +. Should be like the below.
s4 = 'insert into student select RollNumber, FirstName,CSubjectCode, ' &
+ 'Internal_1,Mentor ' &
+ 'FROM Marks_Final ' &
+ 'WHERE (Internal_1 is not null) and ' &
+ '(feeactive=~"Y~") and mentor=~"' +mid+'~"' &
+ 'GROUP BY RollNumber'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sathy,
Try replacing the variable mid with a different name (maybe ls_mid). The query might be confusing it with the function MID.
HTH,
Manuel Marte
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Sathy,
Some suggestions:
+ Use MessageBox() to display s4 and see if the INSERT statement is correct
+ Use the backslash escape character for the variable mid and replace doublequotes by single ones:
and mentor=\' + mid + \' &
+ ' GROUP BY RollNumber'
P.S: I think there is one blank missing in the GROUP statement
Hope this helps
Jacob
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
24 | |
11 | |
9 | |
7 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.