SQL链接数据库
Standard Security:
"Data Source=Aron1;Initial
Catalog=pubs;User Id=sa;Password=asdasd;"
- or -
"Server=Aron1;Database=pubs;User
ID=sa;Password=asdasd;Trusted_Connection=False"
(both
connection strings produces the same result)
Trusted Connection:
"Data
Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"
- or -
"Server=Aron1;Database=pubs;Trusted_Connection=True;"
(both connection strings produces the same result)
(use serverName\instanceName as Data Source to use
an specifik SQLServer instance)
Connect via an IP
address:
"Data Source=190.190.200.100,1433;Network
Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"
(DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the
Data Source is the port to use (1433 is the default))
Enabling MARS (multiple active result sets):
"Server=Aron1;Database=pubs;Trusted_Connection=True;MultipleActiveResultSets=true"
Note! Use &nbs
相关文档:
#include "iostream.h"
#include "stdio.h"
#import "C:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
int main(int argc, char* argv[])
{
::CoInitialize(NULL);
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance("ADODB.Connection");
tr ......
Case具有两种格式。简单Case函数和Case搜索函数。
--简单Case函数
CASE sex
WHEN '1' THEN '男'
WHEN '2' THEN '女'
ELSE '其他' END
--Case搜索函数
CASE WHEN sex = '1' THEN '男'
&nbs ......
--跨服务器查询如下:
SELECT a.*,b.stor_Name
from OPENROWSET('MSDASQL',
'DRIVER={SQL Server};SERVER=tom;UID=sa;PWD=123',
pubs.dbo.authors) AS a,stores b
ORDER BY a.au_lname, a.au_fname
--其中,tom为远程服务器名,stores 是本机数据库pubs中的表
--需要注意的是若二个表中的 ......
表:用户号码,登录时间
显示 :每日登录各时间段的登录人数,和每天登录人数
if isnull(object_id('#tb'),'')=''
drop table #tb
CREATE TABLE #tb(列名1 varchar(12),时间 datetime)
INSERT INTO #tb
SELECT '03174190188','2009-11-01 07:17:39.217' UNION ALL
SELECT '015224486575','2009-11-01 08:01:17.153' ......
【1】
create procedure proc_pager1
( @pageIndex int, -- 要选择第X页的数据
@pageSize int -- 每页显示记录数
)
AS
BEGIN
declare @sqlStr varchar(500)
set @sqlStr='select top '+con ......