列名作为参数 [英] column name as parameter
本文介绍了列名作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些列像text_en,text_es,text_de在SQL表。现在,我想这取决于语言只从一列检索值。
所以,我创建了一个SQL字符串 SELECT @textfield来自以下;表>
而在VB code我用 cmd.AddWithValue(文本框,text_+ LANG)
但SQL返回列的名称,而不是该列的值。我怎样才能获得价值?
I have some columns like text_en, text_es, text_de in a SQL table. Now I want to retrieve the value from just one column depending on the language.
So I created an sql string
SELECT @textfield FROM <table>
and in the vb code I use
cmd.AddWithValue("textfield", "text_" + lang)
But sql returns the name of the column instead of the value of that column. How can I get the value?
推荐答案
您也可以做
SELECT CASE @textfield
WHEN 'text_en' THEN text_en
WHEN 'text_es' THEN text_es
WHEN 'text_de' THEN text_de
END AS local_text
FROM TableName
这篇关于列名作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文