SELECT语句中的SQL变量

时间:2018-08-03 16:49:10

标签: variables sql-manager

这似乎应该很简单,但是我做错了。我想声明一个值,以便可以在顶部输入一次,然后在整个代码中使用它。

下面是一个简单的代码版本,但是它不起作用。运行它时没有任何结果,但是如果取出class NotificationRetrieveSerializer(serializers.ModelSerializer): content_object = NotificationRelatedField(read_only=True) class Meta: model = Notification fields = [ 'id', 'created_at', 'is_read', 'type', 'content_object', ] # override to_representation method def to_representation(self, instance): # python3 for `super` call result = super().to_representation(instance) # python2 for `super` call # result = super( # NotificationRetrieveSerializer, self # ).to_representatio(instance) # here you call your field's `to_representation` with current instance # as the argument rather than as the `value` of the field. result['content_object'] = content_object_field.to_representation(instance) return result class NotificationRelatedField(serializers.RelatedField): # here `value` is now the `Notification` instance def to_representation(self, value): data = {} # get the type and this field's value type = value.type content_object = value.content_object return data 并手动进行设置,则会得到结果:

declare

这是我尝试过的。

如上所述,我没有从查询中得到任何结果。它应该为我提供declare @orderno varchar set @orderno = '739724' SELECT ORDSIG.* FROM ordsig WHERE ORDER_NO = @orderno 的数据,但事实并非如此。当我删除Order_NO并将其设置为常数Order_no = @orderno时,我得到一些数据结果。

0 个答案:

没有答案