Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

sql inÎÊÌâ

listidÊÇintÊý¾Ý
declare @listid nvarchar(100)
set @listid='(1,2,3,7,9,10)'
select * from forums where listid in(@listid)ʱÌáʾÈçÏ´íÎó£º
ÔÚ½« nvarchar Öµ '(1,2,3,7,9,10)' ת»»³ÉÊý¾ÝÀàÐÍ int ʱʧ°Ü¡£

µ«
declare @sql nvarchar(200)
declare @listid nvarchar(100)
set @listid='(1,2,3,7,9,10)'
set @sql='select * from forums where listid in(' + @listid + ')'
exec(@sql)
¾Í²»»áÓÐ´í¡£

listidÊÇintÊý¾Ý
declare @listid nvarchar(100)
set @listid='(1,2,3,7,9,10)'
select * from forums where listid in(@listid)ʱÌáʾÈçÏ´íÎó£º
ÔÚ½« nvarchar Öµ '(1,2,3,7,9,10)' ת»»³ÉÊý¾ÝÀàÐÍ int ʱʧ°Ü¡£

µ±È»À²,Õâ¸ö»áĬÈÏת³ÉLISTIDÀàÐÍ,ת²»¹ý¾Í±¨´íÁË,
ÓÃCHARINDEX»ò¶¯Ì¬EXEC

charindexÎÒÊÔ¹ý£¬µ«µ±@listid='12'ʱ
»á°Ñlistid=1,2,12µÄ¶¼»áÁгöÀ´

SQL code:
--TRY
select * from forums where charindex(','+ltrim(listid)+',',','+@listid+',')


ÒýÓÃ
charindexÎÒÊÔ¹ý£¬µ«µ±@listid='12'ʱ
»á°Ñlistid=1,2,12µÄ¶¼»áÁгöÀ´

CHARINDEX(','+LISTID+',',','+@LISTID+',')>0

ÒýÓÃ
SQL code--TRYselect*from forumswherecharindex('


Ïà¹ØÎÊ´ð£º

javaÁ¬½Ósql 2005ÎÊÌâ ÔÚÏߵȡ£¡£¡£¡£


import java.sql.*;

public class Test {
public static void main(String[] srg) {
  String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";  //¼ÓÔØJDBC ......

SQLÓï¾äÕýÈ·µ«ÊÇRESULTSETÖÐûÓÐÖµ

StringBuffer str = new StringBuffer("select * from menu where parentid=1 and mid <>1 order by parentid");

List list = new ArrayList();
ResultSet rst = null;
DataBa ......

sqlÊý¾Ý¸²¸Ç£¡

ÔõôʹÎÒÿ´Î²»ÊǸüÐÂÊý¾Ý¿â
¶øÊǸ²¸ÇÉϴεÄËùÓмÇÂ¼ÄØ£¡
ÒòΪÓÐʱºòʱ¼äÌõ¼þ²»Í¬
SQL code:

select * from hwouttb where
CAST(REPLACE(REPLACE(REPLACE(outdate,'Äê','-' ),'ÔÂ','-'),'ÈÕ','') AS ......

Çó½ÌÒ»¸öSql²éѯÎÊÌâ¡£

ÓÐÈý¸ö±íÒ»¸öÊDzɹºµ¥¸ñʽÈçÏÂ
Èë¿âµ¥±í£º

Èë¿âµ¥ºÅ      ²úÆ·        Öʼì±àºÅ      Èë¿âÊýÁ¿
001          Æ·ÖÖ1&n ......

Çë½Ìsql¸ßÊÖ,¹ØÓÚms-sqlserverËø»úÖÆ

SQL code:

declare @cnt int
select @cnt=count(1) from TableTest
if(@cnt==0)
insert into TableTest values(1,'abc')


¶ÔÓÚÕâÑùµÄÒ»¶Îsql²¢·¢Ö´ÐÐʱ,Ó¦¸ÃÓпÉÄܲåÈëÖØ¸´¼Ç¼
²»ÖªµÀ´ó¼ÒÊÇÔõô· ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ