宣告一個變數 (Ex: declare @para) ,會採用DB Server的collation, 還是使用 DB 的 collation setting

朋友的問題,而我的測試如下:
 

宣告變數時,連接當下落在哪個 DB,就用該 DB 所定義的 Collation ,但在比較時,可以直接指定 collate,而不管預設的 collate

 

SELECT *

FROM fn_helpcollations() where name like ‘Chinese_Taiwan_Stroke%’

 

create database db1 collate Chinese_Taiwan_Stroke_BIN

go

create database db2 collate Chinese_Taiwan_Stroke_CI_AI

GO

 

use db1

go

declare @c nvarchar(1),@b bit

set @c=’a’

if @c=’A’  分大小寫

        select ‘不分大小寫

else

        select ‘分大小寫

 

你可以在比較的地方指定 collate ,不管是 where if

if @c=’A’ collate Chinese_Taiwan_Stroke_CI_AI

        select ‘不分大小寫

else

        select ‘分大小寫

go

 

use db2

go

declare @c nvarchar(1),@b bit

set @c=’a’

if @c=’A’  不分大小寫

        select ‘不分大小寫

else

        select ‘分大小寫

go

 

USE Master

GO

DROP DATABASE db1,db2

One Comment

  1. Unknown
    Posted 2008 年 09 月 07 日 at 05:13:17 | Permalink | 回覆

    Hi,Do you need advertising displays, screen advertisings, digital sign, digital signages and LCDs? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.
    amberdigital Contact Us
    E-mail:sstar@netvigator.com
    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[dc

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: