本文介绍了使用sql server查询获取描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 表名studentdetails studid课程代码说明 1000 AFF高级消防 2000 MC medicare 表名SMSDetails studid关键字Msgdelivered 1000 HIMT AFF是 2000 HIMT MC是 使用上面的两个表我想得到描述(来自studentdetails表)和Msgdelivered(来自SMSDetails表)。 为此我写了如下查询 选择s.studid,s.Description,c.Msgdelivered来自studentdetails s,SMSDetails c其中s.studid = c.studid和s.coursecode = RIGHT(c.keyword) ,4) 当我运行以上查询显示输出如下时,没有任何输出即将来临 studid description MSgdelivered 但是当我执行以下查询时如下 select s.studid ,s.Description,c.Msgdelivered from studentdetails s,SMSDetails c其中s.studid = c.studid studid description MSgdelivered 1000高级消防是 2000医疗保险是 选择s.studid,s.Description,c。 Msgdelivered来自studentdetails s,SMSDetails c其中s.studid = c.studid和s.coursecode = RIGHT(c.keyword,4) 请问有什么问题我上面的查询使用上面的查询在右边修剪关键字从SMSdetails表有什么问题。 问候, Narasiman P.Table name studentdetails studid coursecode Description 1000 AFF advanced fire fighting 2000 MC medicareTable name SMSDetails studid keyword Msgdelivered 1000 HIMT AFF yes 2000 HIMT MC yesusing above two table i want to get the Description (from studentdetails table) and Msgdelivered (from SMSDetails table).for that i written the query as follows select s.studid,s.Description,c.Msgdelivered from studentdetails s,SMSDetails c where s.studid=c.studid and s.coursecode= RIGHT(c.keyword,4)When i run the above query shows output as follows nothing no output is coming studid description MSgdeliveredBut when i execute the below query as follows select s.studid,s.Description,c.Msgdelivered from studentdetails s,SMSDetails c where s.studid=c.studidstudid description MSgdelivered1000 advanced fire fighting Yes2000 medicare Yes select s.studid,s.Description,c.Msgdelivered from studentdetails s,SMSDetails c where s.studid=c.studid and s.coursecode= RIGHT(c.keyword,4)please what is the problem in my above query using above query in Right trim the keyword from SMSdetails table what is the problem.Regards,Narasiman P.推荐答案你需要使用JOIN 试试这个:You need to use a JOINTry this:SELECT sd.studid, sd.Description, smd.MsgdeliveredFROM SMSDetails smdJOIN studentdetails sdON SUBSTRING(smd.keyword, 6, 3)=sd.coursecode应该做你想做的事。根据你的数据,你必须使用RIGHT(c.keyword,3)而不是RIGHT(c.keyword,4),否则使用ltrim(右(c.keyword,4))修剪左侧空间As per your data you have to use RIGHT(c.keyword,3) instead of RIGHT(c.keyword,4), or else use ltrim(RIGHT(c.keyword,4)) to trim the left hand side space 这篇关于使用sql server查询获取描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-05 09:12