1. Sql语句中类型转换
使用convert进行数据转换,例如
update Parts set PartsDescription=CONVERT(varchar(10),ID)+'-----' +PartsDescription;
上例中将整型转换为字符串。
2. 获取最大的某个字段值
select max(字段) from 表名。
3. The INSERT statement conflicted with the CHECK constraint "inventorygoodcons". The conflict occurred in database "DB_INTEL_DFIT3", table "dbo.Parts", column 'InventoryGood'. 出现此类错误是因为数据库中有对此字段的限制,我们可以使用此命令查看限制条件
SELECT
name, definition
FROM
sys.check_constraints
WHERE
name = 'inventorygoodcons'
4. 获得某个字段重复的记录
select * from PO where PONo in( select PONo from PO group by PONo having COUNT(pono)>1 )
5. 获得多个字段重复的记录
select p1.* from Parts p1,Parts p2 where p1.ID <>p2.ID and p1.PartNo=p2.PartNo and p1.PartsCenterID=p2.PartsCenterID