我正在尝试过滤varchar列上的数字范围。我有一个电视产品名称列表,并希望将它们放入大小的桶中,例如: “42英寸或更小”。是否可以在此声明中使用类似< = 42的内容?
namespace TrialForDatabase
{
public partial class Form1 : Form
{
SqlConnection sc = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename='C:\\Users\\flex\\Documents\\Visual Studio 2015\\Projects\\Inventory\\Inventory\\inventory.mdf';Integrated Security=True;Connect Timeout=30");
SqlCommand cmd;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
sc.Open();
cmd = new SqlCommand("SELECT maincategory_name FROM maincategory", sc);
textBox1.Text = cmd.ToString();
sc.Close();
}
}
}
like语句还需要包含文本,因为模型名称可以包含其他数字,我不想在50英寸的存储桶中捕获标题为“Samsung 40 inch tv model 1250”的电视。
任何想法都会非常感激!
谢谢, FAB
答案 0 :(得分:-1)
根据新数据更新。
with table1 as
(
select '45 inches' as title from dual
union
select '36 inches' from dual
union
select 'Panasonic TX-40C300B 1080p Full HD LED 40 Inch TV' from dual union
select 'UE40H5000 40" Full HD LED Backlit TV' from dual union
select 'Samsung Series 6 JU6500 Smart 4K Ultra HD Curved LED 40 Inch TV' from dual
)
select case when trimsize <= 42
THEN '42 inches or smaller'
ELSE 'Greater than 42 inches'
end as TV_Type
from(
select case when instr(upper(title),'INCH') > 0 then
trim(substr(title,instr(upper(title),'INCH')-4,3))
when instr(title,'"') > 0 then
trim(substr(title,instr(title,'"')-2,2))
end as trimsize
from table1) tmp1
首先,我决定您的输入字符串是否包含"
或INCH
个关键字。基于此我正在采取先前的值并修剪它。
注意:如果你有40到英寸之间的额外空格,那么这是行不通的。此外,如果电视尺寸为3位数,则可能无效。但除此之外,你应该做得很好。