Friday, March 30, 2012
Jobbing!
values) where in the date is 1 + today's date. For e.g. today is
20/09/2005. I want all those records where the date is 21/09/2005.
I want to send a reminder mail to all those records retrieved that they
have to make the payment latest by tomorrow which is the due date.
That's the reason why I am fetching all those records where the date is
1 + today's date. I am implementing this by creating a job & scheduling
it to run everyday at one particular time. This is the code:
---
DECLARE
@.getduedate varchar(20),
@.msg varchar(3000),
@.email varchar(100),
@.person varchar(50)
SET @.getduedate=(SELECT DDate FROM MyTable WHERE
DDate=CONVERT(char(20),GETDATE()+1,1)))
IF (@.getduedate<>"")
BEGIN
SET @.email=(SELECT EMail FROM MyTable WHERE
DDate=CONVERT(char(20),GETDATE()+1,1))
SET @.person=(SELECT Person FROM MyTable WHERE
DDate=CONVERT(char(20),GETDATE()+1,1))
SET @.msg='To ' + @.person + ','
SET @.msg=@.msg + 'Your payment is due for tomorrow.'
EXEC master.dbo.xp_sendmail
@.recipients=@.email,
@.subject='Payment Due Date Reminder!',
@.message=@.msg
END
---
But the above generates the "Subquery returned more than 1 value" error
when more than 1 record matches the criteria. How do I resolve this?
Thanks,
Arpan
You have to do that in a loop if it contains more than one rows
(untested)
DECLARE
@.getduedate varchar(20),
@.msg varchar(3000),
@.email varchar(100),
@.person varchar(50),
@.RowCount int,
@.I INT
SET @.I = 0
CREATE TABLE #Mails
(
Counter INT identity(1,1),
DDate varchar(200),
EMail varchar(200),
Person varchar(200)
)
INSERT INTO #Mails(DDate,EMail,Person)
SELECT DDate,EMail,Person FROM MyTable WHERE
DDate=CONVERT(char(20),GETDATE()+1,1)
SET @.Rowcount = @.@.Rowcount
WHILE @.I < @.RowCount
BEGIN
Select @.getduedate= DDate,
@.email = EMail,
@.person = Person,
@.msg = 'To ' + @.person + ',' + 'Your payment is
due for tomorrow.'
FROM #Mails
Where Counter = @.I
EXEC master.dbo.xp_sendmail
@.recipients=@.email,
@.subject='Payment Due Date Reminder!',
@.message=@.msg
END
HTH, jens Suessmeyer.|||Sorry should be :
WHILE @.I <= @.RowCount|||Thanks, Jens, for your help although a couple of minor issues gave me a
big headache :-)
There was no code to increment the variable @.l at the end of the WHILE
loop which was why it created an infinite loop!
Secondly the temp table #Mails is being created with an Identity column
initialized to 1 & incrementing by 1 for subsequent records but you
have initialized @.l to 0 which is why the job wasn't succeeding since
xp_sendmail wasn't getting any value for the mandatory @.email parameter
when @.l=0!
Anyways, thanks a lot once again for your help. I really appreciate the
efforts & time you have put in to help me out.
BTW, isn't there any other approach other than what you have shown (no
cursors......please)?
Regards,
Arpan
Friday, March 23, 2012
Job Schedule
I use Enterprise Manager and sort by that column, they are not sorted
correctly.
Suggestions?Hopefully following query can give you the required result.
select sj.name, sj.description,
case sj.enabled
when 0 then 'Enabled'
else 'Disabled' end as 'Job Status',
sjs.next_run_date,
right('000000' + convert(varchar(6),sjs.next_run_time),6) 'Next Run Time'
from msdb.dbo.sysjobs sj, msdb.dbo.sysjobschedules sjs
where sj.job_id = sjs.job_id
order by sjs.next_run_date, sjs.next_run_time
Please let us know whether this helped you or not?
"John Carlton" wrote:
> I would like to view all the scheduled jobs , sorted by Next Run Date. When
> I use Enterprise Manager and sort by that column, they are not sorted
> correctly.
> Suggestions?|||Yes, perfect. Thanks!
"Absar Ahmad" wrote:
> Hopefully following query can give you the required result.
> select sj.name, sj.description,
> case sj.enabled
> when 0 then 'Enabled'
> else 'Disabled' end as 'Job Status',
> sjs.next_run_date,
> right('000000' + convert(varchar(6),sjs.next_run_time),6) 'Next Run Time'
> from msdb.dbo.sysjobs sj, msdb.dbo.sysjobschedules sjs
> where sj.job_id = sjs.job_id
> order by sjs.next_run_date, sjs.next_run_time
> Please let us know whether this helped you or not?
> "John Carlton" wrote:
> > I would like to view all the scheduled jobs , sorted by Next Run Date. When
> > I use Enterprise Manager and sort by that column, they are not sorted
> > correctly.
> > Suggestions?
Job Schedule
I use Enterprise Manager and sort by that column, they are not sorted
correctly.
Suggestions?Hopefully following query can give you the required result.
select sj.name, sj.description,
case sj.enabled
when 0 then 'Enabled'
else 'Disabled' end as 'Job Status',
sjs.next_run_date,
right('000000' + convert(varchar(6),sjs.next_run_time),6) 'Next Run Time'
from msdb.dbo.sysjobs sj, msdb.dbo.sysjobschedules sjs
where sj.job_id = sjs.job_id
order by sjs.next_run_date, sjs.next_run_time
Please let us know whether this helped you or not?
"John Carlton" wrote:
> I would like to view all the scheduled jobs , sorted by Next Run Date. Wh
en
> I use Enterprise Manager and sort by that column, they are not sorted
> correctly.
> Suggestions?|||Yes, perfect. Thanks!
"Absar Ahmad" wrote:
[vbcol=seagreen]
> Hopefully following query can give you the required result.
> select sj.name, sj.description,
> case sj.enabled
> when 0 then 'Enabled'
> else 'Disabled' end as 'Job Status',
> sjs.next_run_date,
> right('000000' + convert(varchar(6),sjs.next_run_time),6) 'Next Run Time'
> from msdb.dbo.sysjobs sj, msdb.dbo.sysjobschedules sjs
> where sj.job_id = sjs.job_id
> order by sjs.next_run_date, sjs.next_run_time
> Please let us know whether this helped you or not?
> "John Carlton" wrote:
>
Job Schedule
I use Enterprise Manager and sort by that column, they are not sorted
correctly.
Suggestions?
Hopefully following query can give you the required result.
select sj.name, sj.description,
case sj.enabled
when 0 then 'Enabled'
else 'Disabled' end as 'Job Status',
sjs.next_run_date,
right('000000' + convert(varchar(6),sjs.next_run_time),6) 'Next Run Time'
from msdb.dbo.sysjobs sj, msdb.dbo.sysjobschedules sjs
where sj.job_id = sjs.job_id
order by sjs.next_run_date, sjs.next_run_time
Please let us know whether this helped you or not?
"John Carlton" wrote:
> I would like to view all the scheduled jobs , sorted by Next Run Date. When
> I use Enterprise Manager and sort by that column, they are not sorted
> correctly.
> Suggestions?
|||Yes, perfect. Thanks!
"Absar Ahmad" wrote:
[vbcol=seagreen]
> Hopefully following query can give you the required result.
> select sj.name, sj.description,
> case sj.enabled
> when 0 then 'Enabled'
> else 'Disabled' end as 'Job Status',
> sjs.next_run_date,
> right('000000' + convert(varchar(6),sjs.next_run_time),6) 'Next Run Time'
> from msdb.dbo.sysjobs sj, msdb.dbo.sysjobschedules sjs
> where sj.job_id = sjs.job_id
> order by sjs.next_run_date, sjs.next_run_time
> Please let us know whether this helped you or not?
> "John Carlton" wrote:
sql
Wednesday, March 21, 2012
job in SQL
Hi..
I am working with an auction site ...I want to ask what I will use to open and close an auction
where the start and end date for the auction is stored in SQL server table...
I read many artical ..I think I will use job ?
can any one help me?
Hi, I'm not very clear about your requirment. Just some questions:
What's the meaning of 'open and close an auction'? Usually such business logic is implemented in application, and we use databases to manage the data, right? Do you mean you have an application to 'perform the auction', and you want to use SQL job to schedule it according to the date stored in some table, so that auctions can be automately opened and closed? Sadly to say it's too complex to use SQL job to do this; while much easier to use an application to control it--your application reads the start/end date from database table, then performs the auction process during the time between start/end date.
|||Hi..
Tank you for reply ...I have an auction site ... the auction will start in the start date that auctioneer decide it( the start date is store in SQL server table when auctioneer create it)...when the auction start it allow the user to bid on it until the end date then the auction will close and it will determine winner that have the highest bid...
what I use to mange opening & closing auction????
|||
Seems you need a project to do this... Other than the 'start time' and 'close time', the auction can also be closed under some conditions: e.g. if some one gives highest price and no one follows up, the auction is finished. So you have to build a project to implement the business of auction; SQL can be used to stored data as backend.
sqlFriday, February 24, 2012
jet oledb from tsql
curent date, then to create 7 tables in the database eg '27 Jul 2006.mdb' on
e
for each day
I then wish to insert rows into these tables,
currently I use managed adox & ado to do this, is it possible to use tsql to
get
sql server write the files from its oledb drivers, and would there be any
problems
doing this
in particular I do not know what arguments to pass to opendatasource to
create a new database.Hello Nick,
I understand that you 'd like to create Access database and access it from
SQL Server via TSQL directly. If it is not correct, let me know.
You may want to create linked server to Access database or use open
openquery/openrowset or four-part name syntax to query access database.
Please refer to teh following links for more informaitoin:
http://msdn2.microsoft.com/en-us/library/ms190479.aspx
287414 You cannot link tables into a Microsoft Access project by using an
ODBC Data Source Name (DSN)
http://support.microsoft.com/defaul...kb;EN-US;287414
As for creating database, it is not feasible to create directly from
opendatasource etc from SQL Server. You need to use adox/ado to do this as
you'v done.
317881 How to create an Access database by using ADOX and Visual C# .NET
http://support.microsoft.com/defaul...kb;EN-US;317881
If you have further questions, please let's know.
Best Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.|||Hello Nick,
I understand that you 'd like to create Access database and access it from
SQL Server via TSQL directly. If it is not correct, let me know.
You may want to create linked server to Access database or use open
openquery/openrowset or four-part name syntax to query access database.
Please refer to teh following links for more informaitoin:
http://msdn2.microsoft.com/en-us/library/ms190479.aspx
287414 You cannot link tables into a Microsoft Access project by using an
ODBC Data Source Name (DSN)
http://support.microsoft.com/defaul...kb;EN-US;287414
As for creating database, it is not feasible to create directly from
opendatasource etc from SQL Server. You need to use adox/ado to do this as
you'v done.
317881 How to create an Access database by using ADOX and Visual C# .NET
http://support.microsoft.com/defaul...kb;EN-US;317881
If you have further questions, please let's know.
Best Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.|||I have posted following question in sqlprogramming but have
not recieved a response so wondered whether I have posted
it correctly
https://msdn.microsoft.com/newsgrou...59-dfac726d711e
Please help,
since the introduction of SQL2005 the default mode for opening access mdb
databases with Openrowset appears to be in exclusive open mode
I wish to open the database in share mode so the other (non net) ADO threads
can open the database at the same time
I only wish to open the database in read only mode
and so to use the mode param
I have tried the following
SELECT COUNT(*)
FROM
OPENROWSET ( 'Microsoft.Jet.OLEDB.4.0',
'"Database = h:\alarmlogfiles\new folder (3)\alarms 04 feb
2007.mdb; Mode = Share Deny None;"'
, 'SELECT [ID],
[System],
[Group],
[Message],
[Acknowledged],
[AckReq],
[Duplicates],
[Group Name],
[Importance],
[Ms],
[Alarm Date],
[LastDupe],
[Viewers],
[Row_Date],
[Colours],
[Status] From [Alarms 08 Feb 2007] Where 1 = 0' )
but get the following error from sql2005 & sql 2000
Server: Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider
"Microsoft.Jet.OLEDB.4.0" for linked server "(null)".
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)"
returned message "Could not find installable ISAM.".
SELECT CustomerID, CompanyName
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb';
'admin';'',Customers)
GO
but there is no opportunity here to add a open mode argument?
please help
best wishes nick
""privatenews"" wrote:
[vbcol=seagreen]
> Hello Nick,
> I understand that you 'd like to create Access database and access it from
> SQL Server via TSQL directly. If it is not correct, let me know.
> You may want to create linked server to Access database or use open
> openquery/openrowset or four-part name syntax to query access database.
> Please refer to teh following links for more informaitoin:
> http://msdn2.microsoft.com/en-us/library/ms190479.aspx
> 287414 You cannot link tables into a Microsoft Access project by using an
> ODBC Data Source Name (DSN)
> http://support.microsoft.com/defaul...kb;EN-US;287414
> As for creating database, it is not feasible to create directly from
> opendatasource etc from SQL Server. You need to use adox/ado to do this as
> you'v done.
> 317881 How to create an Access database by using ADOX and Visual C# .NET
> http://support.microsoft.com/defaul...kb;EN-US;317881
> If you have further questions, please let's know.
> Best Regards,
> Peter Yang
> MCSE2000/2003, MCSA, MCDBA
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ========================================
=============
>
> This posting is provided "AS IS" with no warranties, and confers no rights
.
>
>|||Hello Nick,
Sorry for the late response and it seems there is sync issue in our
internal application for your account. I'v reported this issue to the
related team.
Per your question, I was able to reproduce the issue on my side. It seems
that we are not able to use provider or connection string in the
"datasource" parameter. It also doesn't work if I use provider string
directly:
SELECT CustomerID, CompanyName from
OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Data Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=C:\northwind.mdb;Passord=""',
'select * from customers')
I'v forward your feedback to the product team. In the meantime, I also
encourage you submit via the link below
http://lab.msdn.microsoft.com/produ...ck/default.aspx
Please let's know if you have any further feedback.
Best Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
========================================
==============