1、使用SQL2005的XML类型分拆字符串。
2007年11月小记DECLARE @TagNames XML;
2007年11月小记
SET @TagNames = '<?xml version="1.0" encoding="utf-8"?><ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><string>asp.net</string><string>sql</string><string>ajax</string></ArrayOfString>';
2007年11月小记
2007年11月小记
DECLARE @TagNameTable TABLE([IndexId] INT IDENTITY(1,1NOT NULL PRIMARY KEY[TagName] NVARCHAR(200NOT NULL)
2007年11月小记    
INSERT INTO @TagNameTable
2007年11月小记        
SELECT tab.col.value('text()[1]','nvarchar(200)'AS [TagName]
2007年11月小记        
FROM @TagNames.nodes('/ArrayOfString/string'AS tab(col);
2007年11月小记
2007年11月小记
select * from @TagNameTable order by [IndexId]
2、使网页中所有链接都另页打开
2007年11月小记<head>
2007年11月小记    
<base target="_blank" />
2007年11月小记
</head>
3、Lambda表达式一例
2007年11月小记        static void Main(string[] args)
        }
4、WCF:ABC 从何地以何种方式绑定何种契约
5、如何成功调用wsHttpBinding邦定的WCF服务?
服务器定义了dns,如:
2007年11月小记  <system.serviceModel>
2007年11月小记    
<services>
2007年11月小记      
<service behaviorConfiguration="passportServiceBehavior" name="CJB.Passport.Service.PassportService">
2007年11月小记        
<endpoint address="" binding="wsHttpBinding" contract="CJB.Passport.Contract.IPassportService">
2007年11月小记          
<identity>
2007年11月小记            
<dns value="localhost" />
2007年11月小记          
</identity>
2007年11月小记        
</endpoint>
2007年11月小记        
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
2007年11月小记      
</service>
2007年11月小记    
</services>
2007年11月小记    
<behaviors>
2007年11月小记      
<serviceBehaviors>
2007年11月小记        
<behavior name="passportServiceBehavior">
2007年11月小记          
<serviceMetadata httpGetEnabled="true" />
2007年11月小记          
<serviceDebug includeExceptionDetailInFaults="true" />
2007年11月小记        
</behavior>
2007年11月小记      
</serviceBehaviors>
2007年11月小记    
</behaviors>
2007年11月小记  
</system.serviceModel>
客户端也要配置dns,此dns可以为服务器计算机名称,如:
2007年11月小记    <system.serviceModel>
2007年11月小记        
<client>
2007年11月小记            
<endpoint address="http://passport2.ruiya.com/WcfService/PassportService.svc"
2007年11月小记                binding
="wsHttpBinding" bindingConfiguration="" contract="CJB.Passport.Contract.IPassportService"
2007年11月小记                name
="iisHostEndpoint">
2007年11月小记                
<identity>
2007年11月小记                    
<dns value="cjb"/>
2007年11月小记                
</identity>
2007年11月小记            
</endpoint>
2007年11月小记        
</client>
2007年11月小记    
</system.serviceModel>
或者<dns value="localhost"/>
6、注意between ... and ...在使用变量和使用拼接字符串中不过的执行计划导致的性能问题:
2007年11月小记    declare @handleTime datetime;
2007年11月小记    
declare @beginTime datetime;
2007年11月小记    
declare @endTime datetime;
2007年11月小记    
set @handleTime = DateAdd(day-1getdate());
2007年11月小记    
set @beginTime = CONVERT(datetimeCONVERT(char(10), @handleTime120));
2007年11月小记    
set @endTime = DateAdd(day1@beginTime);
2007年11月小记
2007年11月小记    
declare @sql nvarchar(1000);
2007年11月小记    
set @sql = 'SELECT * FROM [UserPosts] WITH(NOLOCK) WHERE ([AddTime] between ''' +
2007年11月小记        
cast(@beginTime as nvarchar(100)) + ''' AND ''' + cast(@endTime as nvarchar(100)) + ''')';
2007年11月小记    
--print @sql
2007年11月小记
    
2007年11月小记    
declare @st datetime
2007年11月小记    
declare @et datetime
2007年11月小记
2007年11月小记    
set @st = getdate();
2007年11月小记    
exec(@sql);
2007年11月小记    
set @et = getdate();
2007年11月小记    
select datediff(millisecond, @st@et);
2007年11月小记
2007年11月小记    
set @st = getdate();
2007年11月小记    
select * from [UserPosts] WITH(NOLOCK) WHERE ([AddTime] between @beginTime and @endTime);
2007年11月小记    
set @et = getdate();
2007年11月小记    
select datediff(millisecond, @st@et);
拼接字符串: 0ms
使用变量:23106ms
7、SQL拆分字符串
2007年11月小记CREATE PROCEDURE [dbo].[ec_System_SplitString]
2007年11月小记    
@strs nvarchar(4000),
2007年11月小记    
@separator nchar(1)=','
2007年11月小记
AS
2007年11月小记
BEGIN
2007年11月小记    
SET NOCOUNT ON;
2007年11月小记
2007年11月小记    
DECLARE @tbNames    table([Name] nvarchar(256NOT NULL PRIMARY KEY)
2007年11月小记    
DECLARE @Num        int;
2007年11月小记    
DECLARE @Pos        int;
2007年11月小记    
DECLARE @NextPos    int;
2007年11月小记    
DECLARE @Name        nvarchar(256);
2007年11月小记    
SET @Num = 0;
2007年11月小记    
SET @Pos = 1;
2007年11月小记
2007年11月小记    
WHILE(@Pos <= LEN(@strs))
2007年11月小记    
BEGIN
2007年11月小记        
SELECT @NextPos = CHARINDEX(@separator@strs,  @Pos)
2007年11月小记        
IF (@NextPos = 0 OR @NextPos IS NULL)
2007年11月小记            
SELECT @NextPos = LEN(@strs+ 1
2007年11月小记        
SELECT @Name = RTRIM(LTRIM(SUBSTRING(@strs@Pos@NextPos - @Pos)))
2007年11月小记        
SELECT @Pos = @NextPos+1
2007年11月小记
2007年11月小记        
2007年11月小记        
INSERT INTO @tbNames VALUES (@Name)
2007年11月小记        
SET @Num = @Num + 1
2007年11月小记    
END
2007年11月小记
2007年11月小记    
SELECT [Name] FROM @tbNames
2007年11月小记
2007年11月小记
END

相关文章:

  • 2021-08-31
  • 2021-12-15
  • 2021-07-07
  • 2021-09-06
  • 2021-12-01
  • 2021-07-29
  • 2021-07-18
  • 2022-12-23
猜你喜欢
  • 2022-02-24
  • 2022-02-03
  • 2022-01-28
  • 2021-10-01
  • 2022-03-04
  • 2022-02-19
  • 2021-07-02
相关资源
相似解决方案