SQL Server: Select Top 0?

后端 未结 8 1649
谎友^
谎友^ 2020-12-17 07:37

We just came across this in an old production stored proc (there is a lot more going on in here, but this is in one leg of its logic). Why would someone ever select top 0 ro

8条回答
  •  盖世英雄少女心
    2020-12-17 08:09

    Use this to create a temporary table where the collation of your DB and TEMPDB may differ.

    SELECT TOP(0) column INTO #temp FROM [mytable]
    

    Produces a temp table with same collation as my table. This then means

    SELECT * FROM #temp T INNER JOIN [mytable] M ON M.column=T.column
    

    Does not fail due to a collation error.

提交回复
热议问题