当我使用带参数的字符串时,我很难从QSqlQuery获取结果。以下工作正常:
str_filter = "SELECT region_pref FROM ut_users WHERE (user_id = 'ut_user_0000003')"
qr_filter.exec ( str_filter )
但这不是:
str_filter = "declare @userid varchar(15) set @userid = 'ut_user_0000003' " \
"declare @user_region_preference varchar(max) " \
"set @user_region_preference = (SELECT region_pref FROM ut_users WHERE (user_id = @userid)) " \
"select @user_region_preference "
qr_filter.exec ( str_filter )
如果我通过ssms直接在SQL Server上运行它,则按预期运行。 任何帮助将不胜感激。