Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Programming
»
General
»
Insert error - convert failed
Insert error - convert failed
Rate Topic
Display Mode
Topic Options
Author
Message
PritamSalvi
PritamSalvi
Posted Thursday, January 10, 2013 3:23 AM
Forum Newbie
Group: General Forum Members
Last Login: Thursday, June 06, 2013 12:49 AM
Points: 4,
Visits: 25
Hello,
I have one script which displays current running job on the server.
I want to insert this result into a temp table and wants to setup job running out of SLA but i am getting error as below -
Msg 257, Level 16, State 3, Line 9
Implicit conversion from data type sql_variant to varchar is not allowed. Use the CONVERT function to run this query.
Script is as below -
CREATE TABLE #CURRENTJOBS
(SERVER_NAME VARCHAR(200),
JOB_NAME VARCHAR(200),
JOB_RUN_DATE_TIME VARCHAR(200),
CURRENT_RUN_TIME VARCHAR(200),
JOB_RUN_SECONDS INT);
INSERT INTO #CURRENTJOBS
SELECT SERVERPROPERTY('MachineName') AS SERVER_NAME,job.Name AS JOB_NAME ,
CONVERT(Varchar(20),activity.run_requested_Date,109) AS JOB_RUN_DATE_TIME,
RIGHT('0'+CONVERT(VARCHAR(2),((DATEDIFF(ss, activity.Run_requested_Date, GETDATE()))/3600)),2) + ':' +
RIGHT('0'+CONVERT(VARCHAR(2),((DATEDIFF(ss, activity.Run_requested_Date, GETDATE()))%3600)/60),2) + ':' +
RIGHT('0'+CONVERT(VARCHAR(2),((DATEDIFF(ss, activity.Run_requested_Date, GETDATE()))%60)),2) AS CURRENT_RUN_TIME,
(DATEDIFF(ss, activity.Run_requested_Date, GETDATE())) JOB_RUN_SECONDS
FROM msdb.dbo.sysjobs_view job
INNER JOIN msdb.dbo.sysjobactivity activity
ON (job.job_id = activity.job_id)
WHERE run_Requested_date IS NOT NULL AND stop_execution_date IS NULL and Run_requested_Date > GETDATE()-2;
Can you help me.
Post #1405305
PritamSalvi
PritamSalvi
Posted Thursday, January 10, 2013 3:26 AM
Forum Newbie
Group: General Forum Members
Last Login: Thursday, June 06, 2013 12:49 AM
Points: 4,
Visits: 25
I have one more script also to find current running job on the server which i need to insert in the temp table and with using IF else loop i can set email alert notification -
SELECT top 1 j.name as Running_Jobs, ja.Start_execution_date As Starting_time,
datediff(ss, ja.Start_execution_date,getdate())/60 as [Has_been_running(in Min)]
FROM msdb.dbo.sysjobactivity ja
JOIN msdb.dbo.sysjobs j
ON j.job_id=ja.job_id
WHERE job_history_id is null
AND start_execution_date is NOT NULL and start_execution_date > GETDATE() -1
and datediff(ss, ja.Start_execution_date,getdate())/60 > 60
--and j.name like '%gdc%'
ORDER BY start_execution_date
Can somebody help me.
Thanks in advance.
Post #1405308
anthony.green
anthony.green
Posted Thursday, January 10, 2013 3:38 AM
SSCertifiable
Group: General Forum Members
Last Login: Wednesday, June 05, 2013 2:40 AM
Points: 5,075,
Visits: 4,833
PritamSalvi (1/10/2013)
Hello,
I have one script which displays current running job on the server.
I want to insert this result into a temp table and wants to setup job running out of SLA but i am getting error as below -
Msg 257, Level 16, State 3, Line 9
Implicit conversion from data type sql_variant to varchar is not allowed. Use the CONVERT function to run this query.
Script is as below -
CREATE TABLE #CURRENTJOBS
(SERVER_NAME VARCHAR(200),
JOB_NAME VARCHAR(200),
JOB_RUN_DATE_TIME VARCHAR(200),
CURRENT_RUN_TIME VARCHAR(200),
JOB_RUN_SECONDS INT);
INSERT INTO #CURRENTJOBS
SELECT SERVERPROPERTY('MachineName') AS SERVER_NAME,job.Name AS JOB_NAME ,
CONVERT(Varchar(20),activity.run_requested_Date,109) AS JOB_RUN_DATE_TIME,
RIGHT('0'+CONVERT(VARCHAR(2),((DATEDIFF(ss, activity.Run_requested_Date, GETDATE()))/3600)),2) + ':' +
RIGHT('0'+CONVERT(VARCHAR(2),((DATEDIFF(ss, activity.Run_requested_Date, GETDATE()))%3600)/60),2) + ':' +
RIGHT('0'+CONVERT(VARCHAR(2),((DATEDIFF(ss, activity.Run_requested_Date, GETDATE()))%60)),2) AS CURRENT_RUN_TIME,
(DATEDIFF(ss, activity.Run_requested_Date, GETDATE())) JOB_RUN_SECONDS
FROM msdb.dbo.sysjobs_view job
INNER JOIN msdb.dbo.sysjobactivity activity
ON (job.job_id = activity.job_id)
WHERE run_Requested_date IS NOT NULL AND stop_execution_date IS NULL and Run_requested_Date > GETDATE()-2;
Can you help me.
Wrap all your SERVERPROPERY call up into a convert so that it is explicitly casted to VARCHAR, as SQL will not implicitly case it for you.
Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1
&
Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger
Post #1405315
anthony.green
anthony.green
Posted Thursday, January 10, 2013 3:41 AM
SSCertifiable
Group: General Forum Members
Last Login: Wednesday, June 05, 2013 2:40 AM
Points: 5,075,
Visits: 4,833
PritamSalvi (1/10/2013)
I have one more script also to find current running job on the server which i need to insert in the temp table and with using IF else loop i can set email alert notification -
SELECT top 1 j.name as Running_Jobs, ja.Start_execution_date As Starting_time,
datediff(ss, ja.Start_execution_date,getdate())/60 as [Has_been_running(in Min)]
FROM msdb.dbo.sysjobactivity ja
JOIN msdb.dbo.sysjobs j
ON j.job_id=ja.job_id
WHERE job_history_id is null
AND start_execution_date is NOT NULL and start_execution_date > GETDATE() -1
and datediff(ss, ja.Start_execution_date,getdate())/60 > 60
--and j.name like '%gdc%'
ORDER BY start_execution_date
Can somebody help me.
Thanks in advance.
If this is inserting into a temp table, once done create a sp_send_dbmail script underneath it to check if a row exists in the table and if so email the people who need to know
INSERT INTO #Temp
SELECT TOP 1 ...............
IF @@RowCount > 0
BEGIN
EXEC MSDB.dbo.sp_send_dbmail
.....
Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1
&
Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger
Post #1405318
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.