TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kalyani Shevale
NA
3.2k
705.6k
Trigger Probelm
Jul 16 2019 7:13 AM
I have write Trigger but this is not working in
I have used after inserting data that time "
userId
" not getting .
GO
/****** Object:
Trigger
[dbo].[insertCheckInOutTrigger] Script
Date
: 2019-07-15 11:24:57 ******/
SET
ANSI_NULLS
ON
GO
SET
QUOTED_IDENTIFIER
ON
GO
--drop trigger [insertCheckInOutTrigger]
alter
TRIGGER
[dbo].[insertCheckInOutTrigger]
ON
[dbo].[tbl_InOutUser]
AFTER
INSERT
AS
BEGIN
SET
NOCOUNT
ON
;
DECLARE
@Id
INT
,
@checktype
bit
,
@
date
datetime,
@userId
int
,
@createdDate datetime,
@createdBy
INT
,
@EmpId
INT
,
@SN nvarchar(20),
@Sah_UserId
INT
,
@UserSN nvarchar(20),
@SS nvarchar(20),
@idstring nvarchar(20)
SELECT
@Id =[Id],
@checktype =[CheckType],
@
date
=[
Date
],
@userId =[UserId],
@createdDate= [CreatedDate],
@createdBy =[CreatedBy]
FROM
[dbo].[tbl_InOutUser]
SELECT
@EmpId =[EmployeeId]
FROM
[
User
]
WHERE
id=@userId
SELECT
@Sah_UserId=[userid] ,@SN=[SN]
from
[192.168.11.213].adms.[dbo].[userinfo]
WHERE
CONVERT
(
int
, badgenumber)=
CONVERT
(
int
, @EmpId)
SELECT
TOP
1 @UserSN=[SN]
from
[192.168.11.213].adms.[dbo].checkinout
where
userid=@Sah_UserId
and
CONVERT
(
date
, checktime)=
CONVERT
(
date
, getdate());
INSERT
INTO
[192.168.11.213].adms.[dbo].checkinout
(userid,checktime,checktype,verifycode,SN,sensorid,WorkCode,Reserved)
VALUES
(1021,@
date
,
'1'
,
'1'
,
case
when
@UserSN
is
null
then
@SN
else
@UserSN
end
,
'1'
,
null
,
null
)
--INSERT INTO [192.168.11.213].adms.[dbo].checkinout
-- (userid,checktime,checktype,verifycode,SN,sensorid)
-- VALUES(@Sah_UserId,@date,CONVERT(nvarchar(1),@checktype),1,'1','1')
END
--INSERT INTO [192.168.11.213].adms.[dbo].checkinout
-- (userid,checktime,checktype,verifycode,SN,sensorid,WorkCode,Reserved)
-- VALUES(1021,'2019-07-15 14:42:04.110','1','1',case when @UserSN is null then @SN else @UserSN end,'1',null,null)
-- SELECT Sah_UserId=[userid] ,UserSN=[SN]
--from [192.168.11.213].adms.[dbo].[userinfo]
-- WHERE CONVERT(int , badgenumber)=CONVERT(int, '10012333')
please help me..
Reply
Answers (
1
)
What is temporary table in SQL Server
IN clause on SQL-Column-datatype-XML