网事如风 2007-1-4 15:30
[原创] 一个常见Sql问题的解决
[size=2][b][font=宋体][size=12pt]一个常见[/size][/font][/b][b][size=12pt][font=Times New Roman]Sql[/font][/size][/b][b][font=宋体][size=12pt]问题的解决[/size][/font][/b][b][size=12pt][/size][/b][/size]
[b][size=12pt][font=Times New Roman][size=2] [/size][/font][/size][/b]
[size=2][font=宋体]很多时候我们都需要实现如下的功能:[/font][size=10][/size][/size]
[size=10][font=Times New Roman][size=2] [/size][/font][/size]
[size=2][font=宋体]表[/font][size=10][font=Times New Roman]TableM[/font][/size][/size]
[size=2][font=宋体]结构如下:[/font][/size]
[size=2][font=宋体][img]http://p.blog.csdn.net/images/p_blog_csdn_net/SysBug/678.gif[/img][/font][/size]
[size=2][size=10][/size][/size]
[size=10][size=2][/size][/size]
[size=2][font=宋体]数据如下:[/font][/size]
[size=2][size=10][size=10][img]http://p.blog.csdn.net/images/p_blog_csdn_net/SysBug/11.gif[/img][/size][/size][/size]
[size=10][size=2][/size][/size]
[size=2][font=宋体]表[/font][size=10][font=Times New Roman]TableD[/font][/size][/size]
[font=Times New Roman][size=2][size=10] [/size][/size][/font][size=2][font=宋体]结构如下:[/font][size=10][/size][/size]
[size=10][img]http://p.blog.csdn.net/images/p_blog_csdn_net/SysBug/12.gif[/img]
[/size][size=2][font=宋体]数据如下:[/font][size=10][/size][/size]
[b][size=10][size=2][/size][/size][/b]
[b][size=10][font=Times New Roman][size=2] [img]http://p.blog.csdn.net/images/p_blog_csdn_net/SysBug/13.gif[/img][/size][/font][/size][/b]
[size=2][font=宋体]需要实现的功能如下:[/font][/size]
[size=2][size=10] [img]http://p.blog.csdn.net/images/p_blog_csdn_net/SysBug/14.gif[/img][/size][/size]
[size=10][size=2][/size][/size]
[size=2][font=宋体]具体的就不说了,大家仔细看了这几张图就知道实现什么了[/font][size=10][font=Times New Roman]^-^[/font][/size][/size]
[size=10][font=Times New Roman][size=2] [/size][/font][/size]
[size=2][font=宋体]实现起来最直接方法就是用游标了,而且是嵌套游标,这个当然效率相当低了,不过随后会给出更好的实现方法[/font][size=10][font=Times New Roman]^-^[/font][/size][/size]
[size=10][font=Times New Roman][size=2] [/size][/font][/size]
[size=2][font=宋体]这个方法需要建立一个临时表[/font][size=10][font=Times New Roman]TableResult[/font][/size][font=宋体],它只有一个字段[/font][size=10][font=Times New Roman]AllStr!![/font][/size][/size]
[size=10][font=Times New Roman][size=2] [/size][/font][/size]
[size=2][size=10][font=Times New Roman]SQL[/font][/size][font=宋体]代码如下[/font][size=10][font=Times New Roman]:[/font][/size][/size]
[size=2][size=10][font=Times New Roman][/font][/size][/size][size=2][/size][size=2][/size]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][color=#008080]--[/color][color=#008080]方法一:嵌套游标[/color][color=#008080]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#008080]--[/color][color=#008080]表名 字段名[/color][color=#008080]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#008080]--[/color][color=#008080]TableD AStr BStr CStr[/color][color=#008080]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]--[/color][color=#008080]TableM AStr BStr [/color][color=#008080]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]--[/color][color=#008080]TableResult AllStr[/color][color=#008080]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#008080]--[/color][color=#008080]符合条件的数据放到表TheSameRecord[/color][color=#008080]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Select[/color][color=#000000] TableD.AStr,TableD.BStr,TableD.CStr
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Into[/color][color=#000000] TheSameRecord
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]From[/color][color=#000000] TableM,TableD
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Where[/color][color=#000000] TableM.AStr [/color][color=#808080]=[/color][color=#000000] TableD.AStr [/color][color=#808080]And[/color][color=#000000] TableM.BStr [/color][color=#808080]=[/color][color=#000000] TableD.BStr
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Declare[/color][color=#000000] [/color][color=#008000]@AStr[/color][color=#000000] [/color][b]VarChar[/b][color=#000000]([/color][b]50[/b][color=#000000])
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Declare[/color][color=#000000] [/color][color=#008000]@BStr[/color][color=#000000] [/color][b]VarChar[/b][color=#000000]([/color][b]50[/b][color=#000000])
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Declare[/color][color=#000000] [/color][color=#008000]@CStr[/color][color=#000000] [/color][b]VarChar[/b][color=#000000]([/color][b]50[/b][color=#000000])
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Declare[/color][color=#000000] [/color][color=#008000]@AllCStr[/color][color=#000000] [/color][b]VarChar[/b][color=#000000]([/color][b]500[/b][color=#000000])
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Set[/color][color=#000000] [/color][color=#008000]@AllCStr[/color][color=#000000] [/color][color=#808080]=[/color][color=#000000] [/color][color=#ff0000]''[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Declare[/color][color=#000000] [/color][color=#008000]@iNext[/color][color=#000000] [/color][b]Bit[/b][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Set[/color][color=#000000] [/color][color=#008000]@iNext[/color][color=#000000] [/color][color=#808080]=[/color][color=#000000] [/color][b]0[/b][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#008080]--[/color][color=#008080]外层游标[/color][color=#008080]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Declare[/color][color=#000000] Outer_Cursor [/color][color=#0000ff]Cursor[/color][color=#000000] [/color][color=#0000ff]For[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Select[/color][color=#000000] [/color][color=#0000ff]Distinct[/color][color=#000000] AStr,BStr [/color][color=#0000ff]From[/color][color=#000000] TheSameRecord
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Open[/color][color=#000000] Outer_Cursor
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Fetch[/color][color=#000000] [/color][color=#0000ff]Next[/color][color=#000000] [/color][color=#0000ff]From[/color][color=#000000] Outer_Cursor [/color][color=#0000ff]Into[/color][color=#000000] [/color][color=#008000]@AStr[/color][color=#000000], [/color][color=#008000]@BStr[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]While[/color][color=#000000] [/color][b]@@Fetch_Status[/b][color=#000000] [/color][color=#808080]=[/color][color=#000000] [/color][b]0[/b][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Begin[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#008080]--[/color][color=#008080]内层游标[/color][color=#008080]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] [/color][color=#0000ff]Declare[/color][color=#000000] Inner_Cursor [/color][color=#0000ff]Cursor[/color][color=#000000] [/color][color=#0000ff]For[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Select[/color][color=#000000] CStr [/color][color=#0000ff]From[/color][color=#000000] TheSameRecord [/color][color=#0000ff]Where[/color][color=#000000] AStr [/color][color=#808080]=[/color][color=#000000] [/color][color=#008000]@AStr[/color][color=#000000] [/color][color=#808080]And[/color][color=#000000] BStr [/color][color=#808080]=[/color][color=#000000] [/color][color=#008000]@BStr[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Set[/color][color=#000000] [/color][color=#008000]@AllCStr[/color][color=#000000] [/color][color=#808080]=[/color][color=#000000] [/color][color=#ff0000]''[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Open[/color][color=#000000] Inner_Cursor
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Fetch[/color][color=#000000] [/color][color=#0000ff]Next[/color][color=#000000] [/color][color=#0000ff]From[/color][color=#000000] Inner_Cursor [/color][color=#0000ff]Into[/color][color=#000000] [/color][color=#008000]@CStr[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]While[/color][color=#000000] [/color][b]@@Fetch_Status[/b][color=#000000] [/color][color=#808080]=[/color][color=#000000] [/color][b]0[/b][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Begin[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Set[/color][color=#000000] [/color][color=#008000]@AllCStr[/color][color=#000000] [/color][color=#808080]=[/color][color=#000000] [/color][color=#008000]@AllCStr[/color][color=#000000] [/color][color=#808080]+[/color][color=#000000] [/color][color=#008000]@CStr[/color][color=#000000] [/color][color=#808080]+[/color][color=#000000] [/color][color=#ff0000]'[/color][color=#ff0000],[/color][color=#ff0000]'[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Fetch[/color][color=#000000] [/color][color=#0000ff]Next[/color][color=#000000] [/color][color=#0000ff]From[/color][color=#000000] Inner_Cursor [/color][color=#0000ff]Into[/color][color=#000000] [/color][color=#008000]@CStr[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]End[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]if[/color][color=#000000] ([/color][color=#008000]@iNext[/color][color=#000000] [/color][color=#808080]=[/color][color=#000000] [/color][b]0[/b][color=#000000])
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Begin[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Delete[/color][color=#000000] TableResult
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Set[/color][color=#000000] [/color][color=#008000]@iNext[/color][color=#000000] [/color][color=#808080]=[/color][color=#000000] [/color][b]1[/b][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]End[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Insert[/color][color=#000000] [/color][color=#0000ff]Into[/color][color=#000000] TableResult (AllStr) [/color][color=#0000ff]Values[/color][color=#000000] ([/color][color=#ff00ff]SubString[/color][color=#000000]( [/color][color=#008000]@AllCStr[/color][color=#000000],[/color][b]1[/b][color=#000000], [/color][color=#ff00ff]Len[/color][color=#000000]([/color][color=#008000]@AllCStr[/color][color=#000000])[/color][color=#808080]-[/color][b]1[/b][color=#000000]))
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Print[/color][color=#000000] [/color][color=#ff00ff]SubString[/color][color=#000000]( [/color][color=#008000]@AllCStr[/color][color=#000000],[/color][b]1[/b][color=#000000], [/color][color=#ff00ff]Len[/color][color=#000000]([/color][color=#008000]@AllCStr[/color][color=#000000])[/color][color=#808080]-[/color][b]1[/b][color=#000000] )
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Close[/color][color=#000000] Inner_Cursor
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]DealLocate[/color][color=#000000] Inner_Cursor
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Fetch[/color][color=#000000] [/color][color=#0000ff]Next[/color][color=#000000] [/color][color=#0000ff]From[/color][color=#000000] Outer_Cursor [/color][color=#0000ff]Into[/color][color=#000000] [/color][color=#008000]@AStr[/color][color=#000000], [/color][color=#008000]@BStr[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]End[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Close[/color][color=#000000] Outer_Cursor
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]DealLocate[/color][color=#000000] Outer_Cursor
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#008080]--[/color][color=#008080]删除表TheSameRecord[/color][color=#008080]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Drop[/color][color=#000000] [/color][color=#0000ff]Table[/color][color=#000000] TheSameRecord
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Select[/color][color=#000000] [/color][color=#808080]*[/color][color=#000000] [/color][color=#0000ff]From[/color][color=#000000] TableResult
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
结果如下:
[img]http://p.blog.csdn.net/images/p_blog_csdn_net/SysBug/14.gif[/img]
但是马上又想到了另外一种方法实现,因为函数本身就可以对数据进行循环,那么如果用函数来实现的话,
一则效率高,
二则代码量少
那么就有如下实现了:
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][color=#008080]--[/color][color=#008080]方法二:函数[/color][color=#008080]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Create[/color][color=#000000] [/color][color=#0000ff]Function[/color][color=#000000] AddStr([/color][color=#008000]@AStr[/color][color=#000000] [/color][b]VarChar[/b][color=#000000]([/color][b]50[/b][color=#000000]), [/color][color=#008000]@BStr[/color][color=#000000] [/color][b]VarChar[/b][color=#000000]([/color][b]50[/b][color=#000000]))
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Returns[/color][color=#000000] [/color][b]VarChar[/b][color=#000000]([/color][b]8000[/b][color=#000000])
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]As[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Begin[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Declare[/color][color=#000000] [/color][color=#008000]@ALLStr[/color][color=#000000] [/color][b]Varchar[/b][color=#000000]([/color][b]8000[/b][color=#000000])
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Set[/color][color=#000000] [/color][color=#008000]@ALLStr[/color][color=#808080]=[/color][color=#ff0000]''[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Select[/color][color=#000000] [/color][color=#008000]@ALLStr[/color][color=#000000] [/color][color=#808080]=[/color][color=#000000] [/color][color=#008000]@ALLStr[/color][color=#000000] [/color][color=#808080]+[/color][color=#000000] [/color][color=#ff0000]'[/color][color=#ff0000],[/color][color=#ff0000]'[/color][color=#000000] [/color][color=#808080]+[/color][color=#000000] [/color][color=#ff00ff]Cast[/color][color=#000000](CStr [/color][color=#0000ff]As[/color][color=#000000] [/color][b]VarChar[/b][color=#000000]) [/color][color=#0000ff]From[/color][color=#000000] TheSameRecord
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Where[/color][color=#000000] AStr [/color][color=#808080]=[/color][color=#000000] [/color][color=#008000]@AStr[/color][color=#000000] [/color][color=#808080]And[/color][color=#000000] BStr [/color][color=#808080]=[/color][color=#000000] [/color][color=#008000]@BStr[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Set[/color][color=#000000] [/color][color=#008000]@ALLStr[/color][color=#000000] [/color][color=#808080]=[/color][color=#000000] [/color][color=#ff00ff]Right[/color][color=#000000]([/color][color=#008000]@ALLStr[/color][color=#000000],[/color][color=#ff00ff]Len[/color][color=#000000]([/color][color=#008000]@ALLStr[/color][color=#000000])[/color][color=#808080]-[/color][b]1[/b][color=#000000])
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]Return[/color][color=#000000]([/color][color=#008000]@ALLStr[/color][color=#000000])
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]End[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Go[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Select[/color][color=#000000] TableD.AStr,TableD.BStr,TableD.CStr
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Into[/color][color=#000000] TheSameRecord
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]From[/color][color=#000000] TableM,TableD
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Where[/color][color=#000000] TableM.AStr [/color][color=#808080]=[/color][color=#000000] TableD.AStr [/color][color=#808080]And[/color][color=#000000] TableM.BStr [/color][color=#808080]=[/color][color=#000000] TableD.BStr
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Go[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Select[/color][color=#000000] [/color][color=#0000ff]Distinct[/color][color=#000000] AStr,BStr,dbo.AddStr(AStr,BStr) [/color][color=#0000ff]As[/color][color=#000000] AllStr [/color][color=#0000ff]From[/color][color=#000000] TheSameRecord
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]Drop[/color][color=#000000] [/color][color=#0000ff]Table[/color][color=#000000] TheSameRecord
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
结果如下:
[img]http://p.blog.csdn.net/images/p_blog_csdn_net/SysBug/15.gif[/img]
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1420050