2007年11月小記
	
		
		系統
		
		1654 0
	
	  
  
                  1、使用SQL2005的XML類型分拆字符串。 
  
  
  
    
    
      DECLARE
    
    
      ?
    
    
      @TagNames
    
    
      ?XML;
      
      
    
    
      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>
    
    
      '
    
    
      ;
      
      
      
      
    
    
      DECLARE
    
    
      ?
    
    
      @TagNameTable
    
    
      ?
    
    
      TABLE
    
    
      (
    
    
      [
    
    
      IndexId
    
    
      ]
    
    
      ?
    
    
      INT
    
    
      ?
    
    
      IDENTITY
    
    
      (
    
    
      1
    
    
      ,
    
    
      1
    
    
      )?
    
    
      NOT
    
    
      ?
    
    
      NULL
    
    
      ?
    
    
      PRIMARY
    
    
      ?
    
    
      KEY
    
    
      ,?
    
    
      [
    
    
      TagName
    
    
      ]
    
    
      ?
    
    
      NVARCHAR
    
    
      (
    
    
      200
    
    
      )?
    
    
      NOT
    
    
      ?
    
    
      NULL
    
    
      )
      
      
      ????
    
    
      INSERT
    
    
      ?
    
    
      INTO
    
    
      ?
    
    
      @TagNameTable
    
    
      
      
      ????????
    
    
      SELECT
    
    
      ?tab.col.value(
    
    
      '
    
    
      text()[1]
    
    
      '
    
    
      ,
    
    
      '
    
    
      nvarchar(200)
    
    
      '
    
    
      )?
    
    
      AS
    
    
      ?
    
    
      [
    
    
      TagName
    
    
      ]
    
    
      
      
      ????????
    
    
      FROM
    
    
      ?
    
    
      @TagNames
    
    
      .nodes(
    
    
      '
    
    
      /ArrayOfString/string
    
    
      '
    
    
      )?
    
    
      AS
    
    
      ?tab(col);
      
      
      
      
    
    
      select
    
    
      ?
    
    
      *
    
    
      ?
    
    
      from
    
    
      ?
    
    
      @TagNameTable
    
    
      ?
    
    
      order
    
    
      ?
    
    
      by
    
    
      ?
    
    
      [
    
    
      IndexId
    
    
      ]
    
   
   2、使網頁中所有鏈接都另頁打開 
  
  
  
    
    
      <
    
    
      head
    
    
      >
    
    
      
      
      ????
    
    
      <
    
    
      base?
    
    
      target
    
    
      ="_blank"
    
    
      ?
    
    
      />
    
    
      
      
    
    
      </
    
    
      head
    
    
      >
    
   
   3、Lambda表達式一例 
  
  
  
    
    
      ????????
    
    
      static
    
    
      ?
    
    
      void
    
    
      ?Main(
    
    
      string
    
    
      []?args)
      
      
      
      ????????
    
    
      
    
    
      
        {
        
        
        
        ????????????var?strs?
      
      
        =
      
      
        ?
      
      
        new
      
      
        ?List
      
      
        <
      
      
        string
      
      
        >
      
      
        ?
      
      
        
      
      
        
          {?
        
        
          "
        
        
          A1
        
        
          "
        
        
          ,?
        
        
          "
        
        
          A2
        
        
          "
        
        
          ,?
        
        
          "
        
        
          A3
        
        
          "
        
        
          ?}
        
      
      
        ;
        
        
        ????????????List
      
      
        <
      
      
        string
      
      
        >
      
      
        ?list?
      
      
        =
      
      
        ?
      
      
        new
      
      
        ?List
      
      
        <
      
      
        string
      
      
        >
      
      
        ();
        
        
        
        
        ????????????
      
      
        //
      
      
        使用匿名委托
      
      
        
        
        
      
      
        ????????????strs.ForEach(
      
      
        delegate
      
      
        (
      
      
        string
      
      
        ?str)?
      
      
        
      
      
        
          {?Console.WriteLine(str);?}
        
      
      
        );
        
        
        
        
        ????????????
      
      
        //
      
      
        使用Lambda表達式
      
      
        
        
      
      
        ????????????strs.ForEach(x?
      
      
        =>
      
      
        ?list.Add(x.TrimStart(
      
      
        '
      
      
        A
      
      
        '
      
      
        )));
        
        
        ????????????list.ForEach(x?
      
      
        =>
      
      
        ?Console.WriteLine(x));
        
        
        
        
        ????????????Console.ReadLine();
        
        
        ????????}
      
    
   
   4、WCF:ABC 
  
  
    從何地以何種方式綁定何種契約
  
  
   5、如何成功調用 
  
  
    wsHttpBinding
  
  邦定的WCF服務? 
  
  
   服務器定義了dns,如: 
  
  
  
    
    
      ??
    
    
      <
    
    
      system
    
    
      .serviceModel
    
    
      >
    
    
      
      
      ????
    
    
      <
    
    
      services
    
    
      >
    
    
      
      
      ??????
    
    
      <
    
    
      service?
    
    
      behaviorConfiguration
    
    
      ="passportServiceBehavior"
    
    
      ?name
    
    
      ="CJB.Passport.Service.PassportService"
    
    
      >
    
    
      
      
      ????????
    
    
      <
    
    
      endpoint?
    
    
      address
    
    
      =""
    
    
      ?binding
    
    
      ="wsHttpBinding"
    
    
      ?contract
    
    
      ="CJB.Passport.Contract.IPassportService"
    
    
      >
    
    
      
      
      ??????????
    
    
      <
    
    
      identity
    
    
      >
    
    
      
      
      ????????????
    
    
      <
    
    
      dns?
    
    
      value
    
    
      ="localhost"
    
    
      ?
    
    
      />
    
    
      
      
      ??????????
    
    
      </
    
    
      identity
    
    
      >
    
    
      
      
      ????????
    
    
      </
    
    
      endpoint
    
    
      >
    
    
      
      
      ????????
    
    
      <
    
    
      endpoint?
    
    
      address
    
    
      ="mex"
    
    
      ?binding
    
    
      ="mexHttpBinding"
    
    
      ?contract
    
    
      ="IMetadataExchange"
    
    
      ?
    
    
      />
    
    
      
      
      ??????
    
    
      </
    
    
      service
    
    
      >
    
    
      
      
      ????
    
    
      </
    
    
      services
    
    
      >
    
    
      
      
      ????
    
    
      <
    
    
      behaviors
    
    
      >
    
    
      
      
      ??????
    
    
      <
    
    
      serviceBehaviors
    
    
      >
    
    
      
      
      ????????
    
    
      <
    
    
      behavior?
    
    
      name
    
    
      ="passportServiceBehavior"
    
    
      >
    
    
      
      
      ??????????
    
    
      <
    
    
      serviceMetadata?
    
    
      httpGetEnabled
    
    
      ="true"
    
    
      ?
    
    
      />
    
    
      
      
      ??????????
    
    
      <
    
    
      serviceDebug?
    
    
      includeExceptionDetailInFaults
    
    
      ="true"
    
    
      ?
    
    
      />
    
    
      
      
      ????????
    
    
      </
    
    
      behavior
    
    
      >
    
    
      
      
      ??????
    
    
      </
    
    
      serviceBehaviors
    
    
      >
    
    
      
      
      ????
    
    
      </
    
    
      behaviors
    
    
      >
    
    
      
      
      ??
    
    
      </
    
    
      system.serviceModel
    
    
      >
    
   
   客戶端也要配置dns,此dns可以為服務器計算機名稱,如: 
  
  
  
    
    
      ????
    
    
      <
    
    
      system
    
    
      .serviceModel
    
    
      >
    
    
      
      
      ????????
    
    
      <
    
    
      client
    
    
      >
    
    
      
      
      ????????????
    
    
      <
    
    
      endpoint?
    
    
      address
    
    
      ="http://passport2.ruiya.com/WcfService/PassportService.svc"
    
    
      
      
      ????????????????binding
    
    
      ="wsHttpBinding"
    
    
      ?bindingConfiguration
    
    
      =""
    
    
      ?contract
    
    
      ="CJB.Passport.Contract.IPassportService"
    
    
      
      
      ????????????????name
    
    
      ="iisHostEndpoint"
    
    
      >
    
    
      
      
        
        ????????????????
      
    
    
      
        <
      
      
        identity
      
      
        >
      
    
    
      
      
        
        ????????????????????
      
    
    
      
        <
      
      
        dns?
      
      
        value
      
      
        ="cjb"
      
      
        />
      
    
    
      
      
        
        ????????????????
      
    
    
      
        </
      
      
        identity
      
      
        >
      
    
    
      
      
      ????????????
    
    
      </
    
    
      endpoint
    
    
      >
    
    
      
      
      ????????
    
    
      </
    
    
      client
    
    
      >
    
    
      
      
      ????
    
    
      </
    
    
      system.serviceModel
    
    
      >
    
   
  
    或者<dns value="localhost"/>
  
  
   6、注意 
  
  
    between
  
   ... and ...在使用變量和使用拼接字符串中不過的執行計劃導致的性能問題: 
  
  
  
    
    
      ????
    
    
      declare
    
    
      ?
    
    
      @handleTime
    
    
      ?
    
    
      datetime
    
    
      ;
      
      
      ????
    
    
      declare
    
    
      ?
    
    
      @beginTime
    
    
      ?
    
    
      datetime
    
    
      ;
      
      
      ????
    
    
      declare
    
    
      ?
    
    
      @endTime
    
    
      ?
    
    
      datetime
    
    
      ;
      
      
      ????
    
    
      set
    
    
      ?
    
    
      @handleTime
    
    
      ?
    
    
      =
    
    
      ?
    
    
      DateAdd
    
    
      (
    
    
      day
    
    
      ,?
    
    
      -
    
    
      1
    
    
      ,?
    
    
      getdate
    
    
      ());
      
      
      ????
    
    
      set
    
    
      ?
    
    
      @beginTime
    
    
      ?
    
    
      =
    
    
      ?
    
    
      CONVERT
    
    
      (
    
    
      datetime
    
    
      ,?
    
    
      CONVERT
    
    
      (
    
    
      char
    
    
      (
    
    
      10
    
    
      ),?
    
    
      @handleTime
    
    
      ,?
    
    
      120
    
    
      ));
      
      
      ????
    
    
      set
    
    
      ?
    
    
      @endTime
    
    
      ?
    
    
      =
    
    
      ?
    
    
      DateAdd
    
    
      (
    
    
      day
    
    
      ,?
    
    
      1
    
    
      ,?
    
    
      @beginTime
    
    
      );
      
      
      
      
      ????
    
    
      declare
    
    
      ?
    
    
      @sql
    
    
      ?
    
    
      nvarchar
    
    
      (
    
    
      1000
    
    
      );
      
      
      ????
    
    
      set
    
    
      ?
    
    
      @sql
    
    
      ?
    
    
      =
    
    
      ?
    
    
      '
    
    
      SELECT?*?FROM?[UserPosts]?WITH(NOLOCK)?WHERE?([AddTime]?between?
    
    
      '''
    
    
      ?
    
    
      +
    
    
      
      
      ????????
    
    
      cast
    
    
      (
    
    
      @beginTime
    
    
      ?
    
    
      as
    
    
      ?
    
    
      nvarchar
    
    
      (
    
    
      100
    
    
      ))?
    
    
      +
    
    
      ?
    
    
      '''
    
    
      ?AND?
    
    
      '''
    
    
      ?
    
    
      +
    
    
      ?
    
    
      cast
    
    
      (
    
    
      @endTime
    
    
      ?
    
    
      as
    
    
      ?
    
    
      nvarchar
    
    
      (
    
    
      100
    
    
      ))?
    
    
      +
    
    
      ?
    
    
      '''
    
    
      )
    
    
      '
    
    
      ;
      
      
      ????
    
    
      --
    
    
      print?@sql
    
    
      
      
    
    
      ????
      
      
      ????
    
    
      declare
    
    
      ?
    
    
      @st
    
    
      ?
    
    
      datetime
    
    
      
      
      ????
    
    
      declare
    
    
      ?
    
    
      @et
    
    
      ?
    
    
      datetime
    
    
      
      
      
      
      ????
    
    
      set
    
    
      ?
    
    
      @st
    
    
      ?
    
    
      =
    
    
      ?
    
    
      getdate
    
    
      ();
      
      
      ????
    
    
      exec
    
    
      (
    
    
      @sql
    
    
      );
      
      
      ????
    
    
      set
    
    
      ?
    
    
      @et
    
    
      ?
    
    
      =
    
    
      ?
    
    
      getdate
    
    
      ();
      
      
      ????
    
    
      select
    
    
      ?
    
    
      datediff
    
    
      (millisecond,?
    
    
      @st
    
    
      ,?
    
    
      @et
    
    
      );
      
      
      
      
      ????
    
    
      set
    
    
      ?
    
    
      @st
    
    
      ?
    
    
      =
    
    
      ?
    
    
      getdate
    
    
      ();
      
      
      ????
    
    
      select
    
    
      ?
    
    
      *
    
    
      ?
    
    
      from
    
    
      ?
    
    
      [
    
    
      UserPosts
    
    
      ]
    
    
      ?
    
    
      WITH
    
    
      (NOLOCK)?
    
    
      WHERE
    
    
      ?(
    
    
      [
    
    
      AddTime
    
    
      ]
    
    
      ?
    
    
      between
    
    
      ?
    
    
      @beginTime
    
    
      ?
    
    
      and
    
    
      ?
    
    
      @endTime
    
    
      );
      
      
      ????
    
    
      set
    
    
      ?
    
    
      @et
    
    
      ?
    
    
      =
    
    
      ?
    
    
      getdate
    
    
      ();
      
      
      ????
    
    
      select
    
    
      ?
    
    
      datediff
    
    
      (millisecond,?
    
    
      @st
    
    
      ,?
    
    
      @et
    
    
      );
    
   
   拼接字符串: 0ms 
  
  
   使用變量: 
  
  
    23106
  
  ms 
  
  
   7、SQL拆分字符串 
  
  
    
    
      CREATE
    
    
      ?
    
    
      PROCEDURE
    
    
      ?
    
    
      [
    
    
      dbo
    
    
      ]
    
    
      .
    
    
      [
    
    
      ec_System_SplitString
    
    
      ]
    
    
      
      
      ????
    
    
      @strs
    
    
      ?
    
    
      nvarchar
    
    
      (
    
    
      4000
    
    
      ),
      
      
      ????
    
    
      @separator
    
    
      ?
    
    
      nchar
    
    
      (
    
    
      1
    
    
      )
    
    
      =
    
    
      '
    
    
      ,
    
    
      '
    
    
      
      
    
    
      AS
    
    
      
      
    
    
      BEGIN
    
    
      
      
      ????
    
    
      SET
    
    
      ?NOCOUNT?
    
    
      ON
    
    
      ;
      
      
      
      
      ????
    
    
      DECLARE
    
    
      ?
    
    
      @tbNames
    
    
      ????
    
    
      table
    
    
      (
    
    
      [
    
    
      Name
    
    
      ]
    
    
      ?
    
    
      nvarchar
    
    
      (
    
    
      256
    
    
      )?
    
    
      NOT
    
    
      ?
    
    
      NULL
    
    
      ?
    
    
      PRIMARY
    
    
      ?
    
    
      KEY
    
    
      )
      
      
      ????
    
    
      DECLARE
    
    
      ?
    
    
      @Num
    
    
      ????????
    
    
      int
    
    
      ;
      
      
      ????
    
    
      DECLARE
    
    
      ?
    
    
      @Pos
    
    
      ????????
    
    
      int
    
    
      ;
      
      
      ????
    
    
      DECLARE
    
    
      ?
    
    
      @NextPos
    
    
      ????
    
    
      int
    
    
      ;
      
      
      ????
    
    
      DECLARE
    
    
      ?
    
    
      @Name
    
    
      ????????
    
    
      nvarchar
    
    
      (
    
    
      256
    
    
      );
      
      
      ????
    
    
      SET
    
    
      ?
    
    
      @Num
    
    
      ?
    
    
      =
    
    
      ?
    
    
      0
    
    
      ;
      
      
      ????
    
    
      SET
    
    
      ?
    
    
      @Pos
    
    
      ?
    
    
      =
    
    
      ?
    
    
      1
    
    
      ;
      
      
      
      
      ????
    
    
      WHILE
    
    
      (
    
    
      @Pos
    
    
      ?
    
    
      <=
    
    
      ?
    
    
      LEN
    
    
      (
    
    
      @strs
    
    
      ))
      
      
      ????
    
    
      BEGIN
    
    
      
      
      ????????
    
    
      SELECT
    
    
      ?
    
    
      @NextPos
    
    
      ?
    
    
      =
    
    
      ?
    
    
      CHARINDEX
    
    
      (
    
    
      @separator
    
    
      ,?
    
    
      @strs
    
    
      ,??
    
    
      @Pos
    
    
      )
      
      
      ????????
    
    
      IF
    
    
      ?(
    
    
      @NextPos
    
    
      ?
    
    
      =
    
    
      ?
    
    
      0
    
    
      ?
    
    
      OR
    
    
      ?
    
    
      @NextPos
    
    
      ?
    
    
      IS
    
    
      ?
    
    
      NULL
    
    
      )
      
      
      ????????????
    
    
      SELECT
    
    
      ?
    
    
      @NextPos
    
    
      ?
    
    
      =
    
    
      ?
    
    
      LEN
    
    
      (
    
    
      @strs
    
    
      )?
    
    
      +
    
    
      ?
    
    
      1
    
    
      
      
      ????????
    
    
      SELECT
    
    
      ?
    
    
      @Name
    
    
      ?
    
    
      =
    
    
      ?
    
    
      RTRIM
    
    
      (
    
    
      LTRIM
    
    
      (
    
    
      SUBSTRING
    
    
      (
    
    
      @strs
    
    
      ,?
    
    
      @Pos
    
    
      ,?
    
    
      @NextPos
    
    
      ?
    
    
      -
    
    
      ?
    
    
      @Pos
    
    
      )))
      
      
      ????????
    
    
      SELECT
    
    
      ?
    
    
      @Pos
    
    
      ?
    
    
      =
    
    
      ?
    
    
      @NextPos
    
    
      +
    
    
      1
    
    
      
      
      
      
      ????????
      
      
      ????????
    
    
      INSERT
    
    
      ?
    
    
      INTO
    
    
      ?
    
    
      @tbNames
    
    
      ?
    
    
      VALUES
    
    
      ?(
    
    
      @Name
    
    
      )
      
      
      ????????
    
    
      SET
    
    
      ?
    
    
      @Num
    
    
      ?
    
    
      =
    
    
      ?
    
    
      @Num
    
    
      ?
    
    
      +
    
    
      ?
    
    
      1
    
    
      
      
      ????
    
    
      END
    
    
      
      
      
      
      ????
    
    
      SELECT
    
    
      ?
    
    
      [
    
    
      Name
    
    
      ]
    
    
      ?
    
    
      FROM
    
    
      ?
    
    
      @tbNames
    
    
      
      
      
      
    
    
      END
    
   
  
    
      2007年11月小記
    
  
 
 
 	
	
	
	
	
			
	
		
			
				
					更多文章、技術交流、商務合作、聯系博主
					
						微信掃碼或搜索:z360901061
					
					
					
						微信掃一掃加我為好友
						
							QQ號聯系:  360901061
						
					 
				 
			 
		 
	 
	
		
			
				
					您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
					
						【本文對您有幫助就好】元