SQL Server 2005預存程序寫報表舉例

來源:互聯網
上載者:User

    聽說MS SQL 2005內建報表功能,於是我測試了一下,還算比較好用,所以我就錄了一個用預存程序來寫報表的例子。由於測試過程當中沒有語音,所以我在這裡講解一下。

使用的預存程序如下(錄象中到最後我更改了一下預存程序):

使用的資料庫是MS SQL 2000的Northwind資料庫,表是orders。

if exists(select * from sysobjects where name='procTest' and xtype='P')
drop proc procTest
go
create proc procTest
@CustomerId varchar(20)
as
if @CustomerId='*'
select * from Orders
else
select * from Orders where CustomerID=@CustomerId

可以用exec procTest 'VINET' 或者exec procTest '*'來測試

之後建立資料庫報表專案

1、建立資料來源

2、建立新的報表

3、建立資料集,這裡我採用了特殊的方式,因為報表設計介面需要列出欄位,所以我將預存程序中需要輸出的欄位select語句先在資料集運行一下,那麼就得出了紀錄集的所有欄位,而不用自己一個個添加。

4、建立報表的參數CustomerID,設定預設值為*,和預存程序當中判斷語句一致。

5。、更改資料中的語句:="exec procTest '" & Parameters!CustomerID.Value & "'"

6、基本上完成。

在示範中不知道如何按F5出現報表無法現實,但是在預覽中是正常的,大概原理能明白就可以了。關於報表匿名瀏覽的問題網上有介紹,這裡就不多說了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.