Tips for using simple questions

Source: Internet
Author: User
Tags rtrim
1
2 -- ----------------------------------------------------
3 Declare   @ Str   Varchar ( 500 )
4 Set   @ Str = ' Aaa, bbbx, eee, VV '
5 Select   Len ( Replace ( @ Str , ' , ' , ' ,, ' )) -   Len ( @ Str )
6
7
8 -- ----------------------------------------------------
9 Declare   @ B   Bit
10   Set   @ B = 0
11 Select   Substring (N ' No Yes ' , @ B + 1 , 1 )
12
13 -- ----------------------------------------------------
14 Declare   @ IDS   Varchar ( 50 )
15 Set   @ IDS = ' 1, 3 '
16 Select   *   From Userinfo Where   Charindex ( ' , ' + Rtrim (ID) + ' , ' , ' , ' + @ IDS + ' , ' ) > 0   -- Here, why do we need to add a comma before and after the string and ID?
17 -- ----------------------------------------------------
18 Select   *   Into T1 From Userinfo Where   1 = 0
19
20
21 Create   Function F_split ( @ Str   Varchar ( 8000 ), @ Strseprate   Varchar ( 10 ))
22 Returns   @ Temp   Table ( Varchar ( 100 ))
23 As  
24 Begin
25 Declare   @ I   Int
26 Set   @ Str = Rtrim ( Ltrim ( @ Sourcesql ))
27 Set   @ I = Charindex ( @ Strseprate , @ Str )
28 While   @ I > = 1
29 Begin
30 Insert   @ Temp   Values ( Left ( @ Str , @ I - 1 ))
31 Set   @ Str = Substring ( @ Str , @ I + 1 , Len ( @ Str ) - @ I ) -- Of course, you can also rewrite it to stuff here. You can try to rewrite it yourself.
32 Set   @ I = Charindex ( @ Strseprate , @ Str )
33 End
34 If   @ Sourcesql <> ' \ '
35 Insert   @ Temp   Values ( @ Str )
36 Return  
37 End
38
39 -- Create a temporary table to generate a continuous ID.
40 Select   * , Identity ( Int ) Nid Into # T From TB
41
42  
43
44 Select   *   From DBO. f_split ( ' A: B: C: D: E ' , ' : ' )
45

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.