用友erp常用SQL语句.docx

上传人:b****8 文档编号:9377077 上传时间:2023-05-18 格式:DOCX 页数:50 大小:40.92KB
下载 相关 举报
用友erp常用SQL语句.docx_第1页
第1页 / 共50页
用友erp常用SQL语句.docx_第2页
第2页 / 共50页
用友erp常用SQL语句.docx_第3页
第3页 / 共50页
用友erp常用SQL语句.docx_第4页
第4页 / 共50页
用友erp常用SQL语句.docx_第5页
第5页 / 共50页
用友erp常用SQL语句.docx_第6页
第6页 / 共50页
用友erp常用SQL语句.docx_第7页
第7页 / 共50页
用友erp常用SQL语句.docx_第8页
第8页 / 共50页
用友erp常用SQL语句.docx_第9页
第9页 / 共50页
用友erp常用SQL语句.docx_第10页
第10页 / 共50页
用友erp常用SQL语句.docx_第11页
第11页 / 共50页
用友erp常用SQL语句.docx_第12页
第12页 / 共50页
用友erp常用SQL语句.docx_第13页
第13页 / 共50页
用友erp常用SQL语句.docx_第14页
第14页 / 共50页
用友erp常用SQL语句.docx_第15页
第15页 / 共50页
用友erp常用SQL语句.docx_第16页
第16页 / 共50页
用友erp常用SQL语句.docx_第17页
第17页 / 共50页
用友erp常用SQL语句.docx_第18页
第18页 / 共50页
用友erp常用SQL语句.docx_第19页
第19页 / 共50页
用友erp常用SQL语句.docx_第20页
第20页 / 共50页
亲,该文档总共50页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

用友erp常用SQL语句.docx

《用友erp常用SQL语句.docx》由会员分享,可在线阅读,更多相关《用友erp常用SQL语句.docx(50页珍藏版)》请在冰点文库上搜索。

用友erp常用SQL语句.docx

用友erp常用SQL语句

--查询用友版本号

useufsystem

go

select*fromUA_Version

go

-----------------------------------------------------------------

--查看系统用户信息表

useufsystem

select cUser_Idas 操作员编码

cUser_Nameas 操作员名称

nStateas 是否停用 

iAdminas 是否帐套主管理

cDeptas 所属部门

cBelongGrpas 所在组

nStateas 是否停用

fromUA_User

--查看具有帐套主管身份的操作员

select cUser_Idas 操作员编码

cUser_Nameas 操作员名称

fromUA_UserwhereiAdmin=1;

--查看被停用的操作员

select cUser_Idas 操作员编码

cUser_Nameas 操作员名称

fromUA_UserwherenState=1;

--帐套主子表相关信息

useufsystem

--帐套主表

select

 cAcc_Idas 账套号

 cAcc_Nameas 账套名称

 cAcc_Pathas 账套路径

 iYearas 启用会计期年

 iMonthas 启用会计期月

 cAcc_Masteras 账套主管

 cCurCodeas 本币代码

 cCurNameas 本币名称

 cUnitNameas 单位名称

 cUnitAbbreas 单位简称

 cUnitAddras 单位地址

 cUnitZapas 邮政编码

 cUnitTelas 联系

 cUnitFaxas 传真

 cUnitEMailas 电子

 cUnitTaxNoas 税号

 cUnitLPas 法人

 cEntTypeas 企业类型

 cTradeKindas 行业类型

 cIsCompanyVeras 是否集团版

 cDomainas 域名  

 cDescxriptionas 备注  

 cOrgCodeas 机构编码

 iSysIDas 账套部标识

fromua_account

--帐套子表

selectcAcc_Idas 账套号

iYearas 账套年度

 cSub_Idas 模块标识

 bIsDeleteas 是否删除

 bClosingas 是否关闭

 iModiPerias 会计期间

 dSubSysUsedas 启用会计日期

 cUser_Idas 操作员

 dSubOriDateas 启用自然日期

fromua_account_sub

--当客户的数据在其它机器上做的升级然后拷回到原机器

/*拷回的数据,通过‘系统管理’在原机器上引入后,并不会在

ufsystem数据库中的ua_account_sub这个帐套子表中回写上一年度的bClosing字段来关闭上一年度

*/

--比如002帐套结转后年度为2010则用于关闭上一(2009)年度的sql如下:

select*fromua_account_subwherecAcc_Id='002'andiYear=2008

updateua_account_subsetbclosing=0

wherecAcc_Id='002'andiYear=2008

-----------------------------------------------------------------

--清除异常任务及单据锁定

useufsystem

deletefromua_task

deletefromua_tasklog

go

deletefromufsystem..ua_task

deletefromufsystem..ua_tasklog

go

Select* 

Fromua_task 

Where(cacc_id='***') --注:

(***为账套号) 

--科目锁定的解决

/*XX科目已经被用户[XX]锁定”

或“科目(xxxxxx)正在被机器(xxxx)上的用户(xxx)进行(xxxx)操作锁定请稍候再试”。

*/

useUFDATA_002_2008

select ccodeas 科目编码

 cauthas 功能名称

 cuseras 用户名

 cmachineas 机器名

fromGL_mccontrol

deletefromGL_mccontrol

-----------------------------------------------------------------

--如何取得一个数据表的所有列名

/*

方法如下:

先从SYSTEMobxject系统表中取得数据表的SYSTEMID然后再SYSCOLUMN表中取得该数据表的所有列名。

SQL语句如下:

*/

/*(方法一*/

select*fromufsystem..ua_account

select*fromsyscolumnswhereid=obxject_id('ua_account')

declareobjidintobjnamechar(40)

setobjname='ua_account'

selectobjid=idfromsysobxjectswhereid=obxject_id(objname)

select'Column_name'=namefromsyscolumnswhereid=objidorderbycolid

/*(方法二(邹建)*/

---跟踪程序的运行就可以了.  

/*  

开始--程序--MS SQLSERVER  

 --事件探察器(SQL Profiler)  

 --文件

 --新建--跟踪...  

 --设置要跟踪的服务器的信息(连接服务器)--确定

 --设置跟踪的项目...  

 --然后数据库的调用情况就会显示出来

在跟踪项目设置中如果不熟悉的话一般用默认设置

筛选项目有几个可以注意一下:

  

 1.DatabaxseName  同于你要监测的数据库名(不过这个好像不起作用我的电脑上设置无效)  

 2.DatabaxseID    同于你要检测的数据库的dbid可以用  select db_id(N'你要监测的库名')得到dbid  

 3.obxjectName    同于你要监测的对象名例如表名视图名等

 4.obxjectID      同于你要监测的对象的id可以用  select obxject_id(N'你要监测的对象名')得到id  

 5.Error         同于错误如果经常出现某个编号的错误则针对此错误号

 6.Seccess       同于0失败1成功如果是排错就过滤掉成功的处理

*/

/*方法三:

*/

--如果直接查询可以参考我的这段代码:

  

 if exists (select * from dbo.sysobxjects where id = obxject_id(N'[dbo].[p_search]') and obxjectPROPERTY(id N'IsProcedure') = 1)  

 drop procedure [dbo].[p_search]  

 GO  

 /*--搜索某个字符串在那个表的那个字段中

 --邹建  2004.10(引用请保留此信息)--*/  

 /*--调用示例

 use pubs  

 exec p_search N'l'  

 --*/  

 create proc p_search  

 str Nvarchar(1000) --要搜索的字符串

 as  

 if str is null return  

 declare s Nvarchar(4000)  

 create table #t(表名  sysname字段名  sysname)  

 declare tb cursor local for  

 select s='if exists(select 1 from ['+replace(b.name']'']]')+'] where ['+a.name+'] like N''%'+str+'%'')  

 print ''所在的表及字段:

 ['+b.name+'].['+a.name+']'''  

 from syscolumns a join sysobxjects b on a.id=b.id  

 where b.xtype='U' and a.status>=0  

 and a.xtype in(31167)  

 open tb  

 fetch next from tb into s  

 while fetch_status=0  

 begin  

 exec(s)  

 fetch next from tb into s  

 end  

 close tb  

 deallocate tb  

 go  

-----------------------------------------------------------------

-- 通过SQL语句来更改用户的密码

/*修改别人的需要sysadmin role  */

EXEC sp_password NULL 'newpassword' 'User'

/*如果为SA执行*/

EXEC sp_password NULL 'newpassword' sa 

-----------------------------------------------------------------

-- 通怎么判断出一个表的哪些字段不允许为空?

select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where IS_NULLABLE='NO' and TABLE_NAME='ua_account' 

-----------------------------------------------------------------

-- 如何在数据库里找到含有相同字段的表?

--a. 查已知列名的情况

SELECT b.name as TableNamea.name as columnname 

From syscolumns  a INNER JOIN  sysobxjects b  

ON a.id=b.id  

AND b.type='U'  

AND a.name='cacc_id' --本例如:

cacc_id列

--b. 未知列名查所有在不同表出现过的列名

Select o.name As tablenames1.name As columnname 

From syscolumns s1 sysobxjects o 

Where s1.id = o.id 

 And o.type = 'U' 

 And Exists ( 

   Select 1 From syscolumns s2  

   Where s1.name = s2.name  

   And s1.id <> s2.id 

   )

-----------------------------------------------------------------

-- 查询第xxx行数据

-- 假设id是主键:

select * 

from (select top xxx * from yourtable) aa 

where not exists(select 1 from (select top xxx-1 * from yourtable) bb where aa.id=bb.id)

-- 如果使用游标也是可以的

fetch absolute [number] from [cursor_name] 

-- 行数为绝对行数

-----------------------------------------------------------------

--SQLServer日期计算

/*a. 一个月的第一天*/

SELECT DATEADD(mm DATEDIFF(mm0getdate()) 0) 

/*b. 本周的星期一*/

SELECT DATEADD(wk DATEDIFF(wk0getdate()) 0) 

/*c. 一年的第一天*/

SELECT DATEADD(yy DATEDIFF(yy0getdate()) 0) 

/*d. 季度的第一天*/

SELECT DATEADD(qq DATEDIFF(qq0getdate()) 0) 

/*e. 上个月的最后一天 */

SELECT dateadd(ms-3DATEADD(mm DATEDIFF(mm0getdate()) 0)) 

/*f. 去年的最后一天*/

SELECT dateadd(ms-3DATEADD(yy DATEDIFF(yy0getdate()) 0)) 

/*g. 本月的最后一天*/

SELECT dateadd(ms-3DATEADD(mm DATEDIFF(m0getdate())+1 0)) 

/*h. 本月的第一个星期一*/

select DATEADD(wk DATEDIFF(wk0                             

               dateadd(dd6-datepart(daygetdate())getdate())    

             ) 0)   

/*i. 本年的最后一天*/

SELECT dateadd(ms-3DATEADD(yy DATEDIFF(yy0getdate())+1 0))

1.显示本月第一天

SELECTDATEADD(mmDATEDIFF(mm0getdate())0) 

selectconvert(datetimeconvert(varchar(8)getdate()120)+'01'120)

2.显示本月最后一天

selectdateadd(day-1convert(datetimeconvert(varchar(8)dateadd(month1getdate())120)+'01'120))

SELECTdateadd(ms-3DATEADD(mmDATEDIFF(m0getdate())+10)) 

3.上个月的最后一天 

SELECTdateadd(ms-3DATEADD(mmDATEDIFF(mm0getdate())0)) 

4.本月的第一个星期一

selectDATEADD(wkDATEDIFF(wk0dateadd(dd6-datepart(daygetdate())getdate()))0)

5.本年的第一天 

SELECTDATEADD(yyDATEDIFF(yy0getdate())0) 

6.本年的最后一天 

SELECTdateadd(ms-3DATEADD(yyDATEDIFF(yy0getdate())+10))

7.去年的最后一天 

SELECTdateadd(ms-3DATEADD(yyDATEDIFF(yy0getdate())0))

8.本季度的第一天 

SELECTDATEADD(qqDATEDIFF(qq0getdate())0) 

9.本周的星期一 

SELECTDATEADD(wkDATEDIFF(wk0getdate())0) 

10.查询本月的记录 

select*fromtableNamewhereDATEPART(mmtheDate)=DATEPART(mmGETDATE())andDATEPART(yytheDate)=DATEPART(yyGETDATE()) 

11.查询本周的记录 

select*fromtableNamewhereDATEPART(wktheDate)=DATEPART(wkGETDATE())andDATEPART(yytheDate)=DATEPART(yyGETDATE()) 

12.查询本季的记录 

select*fromtableNamewhereDATEPART(qqtheDate)=DATEPART(qqGETDATE())andDATEPART(yytheDate)=DATEPART(yyGETDATE()) 

其中:

GETDATE()是获得系统时间的函数。

13.获取当月总天数:

selectDATEDIFF(ddgetdate()DATEADD(mm1getdate()))

selectdatediff(day

dateadd(mmdatediff(mm''getdate())'')

dateadd(mmdatediff(mm''getdate())'1900-02-01'))

14.获取当前为星期几

DATENAME(weekdaygetdate())

-----------------------------------------------------------------

/*查询数据库的所有用户表*/

useufdata_002_2008

select name from sysobxjects where type='U'

-----------------------------------------------------------------

--查看数据库中所有的触发器

useufdata_002_2008

go

select*fromsysobxjectswherextype='TR'

-----------------------------------------------------------------

--查询特定数据库中某一不知归属表的触发器

/*查询某一个触发器TR_Ap_CloseBills所归属的表*/

useufdata_002_2008

declare parent_obj_id int --定义父对象id变量

--先找出父对象(所在表)的id(在触发器不重复归属于多个表的情况下)

selectparent_obj_id=parent_obj

fromsysobxjectswherename='TR_Ap_CloseBills' 

andxtype='TR' 

print'所在父对象(表)的ID是:

'+str(parent_obj_id)

--接下来找出父对象(表)的名称

selectnameas 触发器所在表为

fromsysobxjectswhere type='U'and id=parent_obj_id

-----------------------------------------------------------------

--查看触发器容

useufdata_002_2008

go

execsp_helptext'TR_Ap_CloseBills' 

-----------------------------------------------------------------

--用于查看触发器的属性(参数指定触发器所在的表)

useufdata_002_2008

go

execsp_helptriggerAp_CloseBills

-----------------------------------------------------------------

--创建触发器

/*

(1)创建一个简单的触发器

触发器是一种特殊的存储过程,类似于事件函数,SQLServer?

 允许为INSERT、UPDATE、DELETE 创建触发器,即当在表中插入、更新、删除记录时,触发一个或一系列 T-SQL语句。

触发器可以在查询分析器里创建,也可以在表名上点右键->“所有任务”->“管理触发器”来创建,不过都是要写 T-SQL 语句的,只是在查询分析器里要先确定当前操作的数据库。

创建触发器用 CREATETRIGGER

格式如下:

------------------------------

CREATETRIGGER 触发器名称

ON 表名

FORINSERT、UPDATE 或 DELETE

AS

   T-SQL 语句

------------------------------

注意:

触发器名称是不加引号的。

*/

--如下是联机丛书上的一个示例,当在 tixtles 表上更改记录时,发送通知 MaryM。

CREATETRIGGERreminder

ONtixtles

FORINSERTUPDATEDELETE 

AS

 EXECmaster..xp_sendmail'MaryM' 

   'Don''tforgettoprintareportforthedistributors.'

/*

(2)删除触发器

用查询分析器删除

在查询分析器中使用 droptrigger 触发器名称来删除触发器。

也可以同时删除多个触发器:

droptrigger 触发器名称触发器名称...

注意:

触发器名称是不加引号的。

在删除触发器之前可以先看一下触发器是否存在:

格式如下:

------------------------------

ifExists(

selectnamefromsysobxjects 

wherename=触发器名称 andxtype='TR'

------------------------

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2