Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

Thursday, March 29, 2012

Embedded select query?

What I'd like to do is use the result of one query as the input for
another. eg:

INSERT INTO foo VALUES (
(SELECT id FROM people WHERE name = "bar"),
10,
'foobar'
) WHERE
id = 1;

Problem is, MSSQL wants a scalar value. Is there a way around this?
Can someone tell me the correct syntax for what I want to do, or is this
something that will have to be done outside SQL?

Err. Hope I've been clear. Thanks for any help you folks can give.Don't use the VALUES clause if you are INSERTing values from a query. It's
also good practice always to specify the column names in an INSERT
statement.

INSERT INTO foo (col1, col2, col3)
SELECT id, 10, 'foobar'
FROM people
WHERE name = 'bar';

I'm not sure what the final WHERE clause in your code was meant to be so
I've left it out. You can't have a WHERE clause on an INSERT statement.

--
David Portas
SQL Server MVP
--|||Eek. It's been a long day I guess. There wasn't supposed to be a where
on that :) But you've answered my question none the less. Thanks.

FYI, I didn't bother with the column specifications for the sake of
simplicity.

Thanks all the same!

David Portas wrote:
> Don't use the VALUES clause if you are INSERTing values from a query. It's
> also good practice always to specify the column names in an INSERT
> statement.
> INSERT INTO foo (col1, col2, col3)
> SELECT id, 10, 'foobar'
> FROM people
> WHERE name = 'bar';
> I'm not sure what the final WHERE clause in your code was meant to be so
> I've left it out. You can't have a WHERE clause on an INSERT statement.

Monday, March 26, 2012

Emailing results from query

Hi,
I just installed sql05 ent version and set up the DB Mail and ran a test
mail without a problem. I also managed to create a job which would execute a
query. I'd like now the sql server send to several email addresses the
results of the query and here where I'm stuck.
HOWDO you do it?
TIA
Ana
Read about sp_send_dbmail.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Ana" <ananospam@.yahoo.es> wrote in message
news:E878A2A8-B75A-4040-A252-DE709E44A372@.microsoft.com...
> Hi,
> I just installed sql05 ent version and set up the DB Mail and ran a test mail without a problem. I
> also managed to create a job which would execute a query. I'd like now the sql server send to
> several email addresses the results of the query and here where I'm stuck.
> HOWDO you do it?
> TIA
> Ana
|||Hi,
This atricle may be of use:
http://builder.com.com/5100-6388-6164310-2.html#Listing%20B
Dan
"Ana" <ananospam@.yahoo.es> wrote in message
news:E878A2A8-B75A-4040-A252-DE709E44A372@.microsoft.com...
> Hi,
> I just installed sql05 ent version and set up the DB Mail and ran a test
> mail without a problem. I also managed to create a job which would execute
> a query. I'd like now the sql server send to several email addresses the
> results of the query and here where I'm stuck.
> HOWDO you do it?
> TIA
> Ana

Emailing results from query

Hi,
I just installed sql05 ent version and set up the DB Mail and ran a test
mail without a problem. I also managed to create a job which would execute a
query. I'd like now the sql server send to several email addresses the
results of the query and here where I'm stuck.
HOWDO you do it?
TIA
AnaRead about sp_send_dbmail.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Ana" <ananospam@.yahoo.es> wrote in message
news:E878A2A8-B75A-4040-A252-DE709E44A372@.microsoft.com...
> Hi,
> I just installed sql05 ent version and set up the DB Mail and ran a test m
ail without a problem. I
> also managed to create a job which would execute a query. I'd like now the
sql server send to
> several email addresses the results of the query and here where I'm stuck.
> HOWDO you do it?
> TIA
> Ana|||Hi,
This atricle may be of use:
http://builder.com.com/5100-6388-61...tml#Listing%20B
Dan
"Ana" <ananospam@.yahoo.es> wrote in message
news:E878A2A8-B75A-4040-A252-DE709E44A372@.microsoft.com...
> Hi,
> I just installed sql05 ent version and set up the DB Mail and ran a test
> mail without a problem. I also managed to create a job which would execute
> a query. I'd like now the sql server send to several email addresses the
> results of the query and here where I'm stuck.
> HOWDO you do it?
> TIA
> Ana

Emailing results from query

Hi,
I just installed sql05 ent version and set up the DB Mail and ran a test
mail without a problem. I also managed to create a job which would execute a
query. I'd like now the sql server send to several email addresses the
results of the query and here where I'm stuck.
HOWDO you do it?
TIA
AnaRead about sp_send_dbmail.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Ana" <ananospam@.yahoo.es> wrote in message
news:E878A2A8-B75A-4040-A252-DE709E44A372@.microsoft.com...
> Hi,
> I just installed sql05 ent version and set up the DB Mail and ran a test mail without a problem. I
> also managed to create a job which would execute a query. I'd like now the sql server send to
> several email addresses the results of the query and here where I'm stuck.
> HOWDO you do it?
> TIA
> Ana|||Hi,
This atricle may be of use:
http://builder.com.com/5100-6388-6164310-2.html#Listing%20B
--
Dan
"Ana" <ananospam@.yahoo.es> wrote in message
news:E878A2A8-B75A-4040-A252-DE709E44A372@.microsoft.com...
> Hi,
> I just installed sql05 ent version and set up the DB Mail and ran a test
> mail without a problem. I also managed to create a job which would execute
> a query. I'd like now the sql server send to several email addresses the
> results of the query and here where I'm stuck.
> HOWDO you do it?
> TIA
> Ana

Emailing Query Results

Is there a way to have SQL server email the results of a Select query to someone?From BOL:

xp_sendmail
Sends a message and a query result set attachment to the specified recipients.

Syntax
xp_sendmail {[@.recipients =] 'recipients [;...n]'}
[,[@.message =] 'message']
[,[@.query =] 'query']
[,[@.attachments =] 'attachments [;...n]']
[,[@.copy_recipients =] 'copy_recipients [;...n]'
[,[@.blind_copy_recipients =] 'blind_copy_recipients [;...n]'
[,[@.subject =] 'subject']
[,[@.type =] 'type']
[,[@.attach_results =] 'attach_value']
[,[@.no_output =] 'output_value']
[,[@.no_header =] 'header_value']
[,[@.width =] width]
[,[@.separator =] 'separator']
[,[@.echo_error =] 'echo_value']
[,[@.set_user =] 'user']
[,[@.dbuse =] 'database']

Emailing query questions

Hello,
I am very new to sql server (as in, still reading the table of contents in
the big honkin' book I bought).
is there a way for users to send an inquiry to an email address, and get a
response from sql server? It would be very helpful if someone could send an
email to parts@.##.com with a part number in the header, and get an email in
response with information on that part.
I also have exchange server 2003, if that helps.
Thanks in advance,I do not know a way in SQL 2005 other than custom coding...
In SQL 2000 there was a stored procedure sp_processmail which could do what
you ask - but you shouldn't use it in new dev because it is going away...
--
Wayne Snyder MCDBA, SQL Server MVP
Mariner, Charlotte, NC
I support the Professional Association for SQL Server ( PASS) and it''s
community of SQL Professionals.
"JohnGregor" wrote:
> Hello,
> I am very new to sql server (as in, still reading the table of contents in
> the big honkin' book I bought).
> is there a way for users to send an inquiry to an email address, and get a
> response from sql server? It would be very helpful if someone could send an
> email to parts@.##.com with a part number in the header, and get an email in
> response with information on that part.
> I also have exchange server 2003, if that helps.
> Thanks in advance,|||<< deep sigh >>
It's never easy.
Thanks for your help, you probably saved me a week of looking.
"Wayne Snyder" wrote:
> I do not know a way in SQL 2005 other than custom coding...
> In SQL 2000 there was a stored procedure sp_processmail which could do what
> you ask - but you shouldn't use it in new dev because it is going away...
> --
> Wayne Snyder MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> I support the Professional Association for SQL Server ( PASS) and it''s
> community of SQL Professionals.
>
> "JohnGregor" wrote:
> > Hello,
> >
> > I am very new to sql server (as in, still reading the table of contents in
> > the big honkin' book I bought).
> >
> > is there a way for users to send an inquiry to an email address, and get a
> > response from sql server? It would be very helpful if someone could send an
> > email to parts@.##.com with a part number in the header, and get an email in
> > response with information on that part.
> >
> > I also have exchange server 2003, if that helps.
> >
> > Thanks in advance,

Thursday, March 22, 2012

Email the results of the query

Hello,

I want to email the results of the query. The query output can be email either as the HTML body of the email to be sent or as a excel attachement.

I am wondering as to what would be the best way to achive this.

a) I could have a email client module in C# or VB.NET 2.0, which would fetch the query resultset and store it in a dataset. I format it as HTML body and send the email using System.NET. For excel, can use XSLT

Please suggest if there is any other approach that would be more suitable.

Thanks.

Check here to view a similar posting from earlier today.|||

Found what I was looking for. So here goes

Solution was Configure Database Mail and then use the msdb.dbo.sp_send_dbmail stored procedure. For your reference http://builder.com.com/5100-6388-6164310.html

Wednesday, March 21, 2012

Email Resultset with sql mail?

I would like to email myself the results of a query once a day. Can I do thi
s
with sql mail? If so, can someone point me in the direction of some
documentation on how to do this?From SQL BOL
This example sends the results of the sp_configure to Robert King.
EXEC xp_sendmail 'robertk', @.query = 'sp_configure'
HTH. Ryan
"Dan" <Dan@.discussions.microsoft.com> wrote in message
news:F035773E-BD7A-43D9-AEF1-3AE09C88F3AD@.microsoft.com...
>I would like to email myself the results of a query once a day. Can I do
>this
> with sql mail? If so, can someone point me in the direction of some
> documentation on how to do this?

Email Resultset with sql mail?

I would like to email myself the results of a query once a day. Can I do this
with sql mail? If so, can someone point me in the direction of some
documentation on how to do this?
From SQL BOL
This example sends the results of the sp_configure to Robert King.
EXEC xp_sendmail 'robertk', @.query = 'sp_configure'
HTH. Ryan
"Dan" <Dan@.discussions.microsoft.com> wrote in message
news:F035773E-BD7A-43D9-AEF1-3AE09C88F3AD@.microsoft.com...
>I would like to email myself the results of a query once a day. Can I do
>this
> with sql mail? If so, can someone point me in the direction of some
> documentation on how to do this?
sql

Email Resultset with sql mail?

I would like to email myself the results of a query once a day. Can I do this
with sql mail? If so, can someone point me in the direction of some
documentation on how to do this?From SQL BOL
This example sends the results of the sp_configure to Robert King.
EXEC xp_sendmail 'robertk', @.query = 'sp_configure'
--
HTH. Ryan
"Dan" <Dan@.discussions.microsoft.com> wrote in message
news:F035773E-BD7A-43D9-AEF1-3AE09C88F3AD@.microsoft.com...
>I would like to email myself the results of a query once a day. Can I do
>this
> with sql mail? If so, can someone point me in the direction of some
> documentation on how to do this?

Email report ONLY if there are records ?

Any idea how to have a Report Subscription only email the report or link if
there are records returned by the reports query or dataset?You would need to do this in a data driven subscription.
Brian Welcker
MSFT
"steve" <steve@.discussions.microsoft.com> wrote in message
news:74944DC2-1C3F-44C0-9E6B-1625D6641E0B@.microsoft.com...
> Any idea how to have a Report Subscription only email the report or link
> if
> there are records returned by the reports query or dataset?
>sql

Email report (or link), only if there are records to be viewed.

Any idea how to have a Report Subscription only email the report or link if
there are records returned by the reports query or dataset?The only way I've seen to do this is with a data driven subscription.
Unfortunately, DDS is not available in non-Enterprise edition
installations. If you can't do DDS, the best you can do is use an
expression like ="No data available to report" in the NoRows property.
The subscription email still goes out but the report contains an
explanatory message instead of a blank page.
HTH
toolman
Corvallis wrote:
> Any idea how to have a Report Subscription only email the report or link if
> there are records returned by the reports query or dataset?|||Hi Corvallis,
Were you able to do this? Have the same need to email the
report ONLY if there are any records. Please let us know.
Best regards,
Steve.
"Corvallis" wrote:
> Any idea how to have a Report Subscription only email the report or link if
> there are records returned by the reports query or dataset?|||Hi Toolman,
Do you have any examples of this
? We need the same logic. Am looking at the step 3 window and the place to
put this in but am not sure.
Thanks, Steve.
"toolman" wrote:
> The only way I've seen to do this is with a data driven subscription.
> Unfortunately, DDS is not available in non-Enterprise edition
> installations. If you can't do DDS, the best you can do is use an
> expression like ="No data available to report" in the NoRows property.
> The subscription email still goes out but the report contains an
> explanatory message instead of a blank page.
> HTH
> toolman
> Corvallis wrote:
> > Any idea how to have a Report Subscription only email the report or link if
> > there are records returned by the reports query or dataset?
>

Monday, March 19, 2012

email notification on job status

In MSDE, since there is no sql mail, I am thinking of doing the following:
1. write a shell script which will query the sysjobhistory table to
determine if any job failed. If so, then an email about the failure is sent
out.
Question: What should my sql command and my mail command look like. I dont
have much experience in shell scripting or am not very familiar with MSDB
database either.
hi,
inquisite wrote:
> In MSDE, since there is no sql mail, I am thinking of doing the
> following:
> 1. write a shell script which will query the sysjobhistory table to
> determine if any job failed. If so, then an email about the failure
> is sent out.
> Question: What should my sql command and my mail command look like. I
> dont have much experience in shell scripting or am not very familiar
> with MSDB database either.
if an SMPT solution is viable, I'd resort on xp_smpt extended stored
procedure provided at http://sqldev.net/xp/xpsmtp.htm
you can then code your task's step to send a mail on success or failure..
SQL Server MVP Tibor Karaszi presents and describes such a feature at
http://www.karaszi.com/sqlserver/info_no_mapi.asp
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.10.0 - DbaMgr ver 0.56.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
|||SMTP solution is not available. That is why I wanted to send an email through
some script running on the server.
"Andrea Montanari" wrote:

> hi,
> inquisite wrote:
> if an SMPT solution is viable, I'd resort on xp_smpt extended stored
> procedure provided at http://sqldev.net/xp/xpsmtp.htm
> you can then code your task's step to send a mail on success or failure..
> SQL Server MVP Tibor Karaszi presents and describes such a feature at
> http://www.karaszi.com/sqlserver/info_no_mapi.asp
> --
> Andrea Montanari (Microsoft MVP - SQL Server)
> http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
> DbaMgr2k ver 0.10.0 - DbaMgr ver 0.56.0
> (my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
> interface)
> -- remove DMO to reply
>
>
|||If an SMTP server is not available then how were you planing to send email?
Jim
"inquisite" <inquisite@.discussions.microsoft.com> wrote in message
news:D7FE12AC-C359-4B74-A8C6-E497686705CB@.microsoft.com...[vbcol=seagreen]
> SMTP solution is not available. That is why I wanted to send an email
> through
> some script running on the server.
> "Andrea Montanari" wrote:

Email Notification

Hi
I run a query against sysjobs table to turn off the email notification, but
still i am getting notification from jobs. Do I need to update any other
table while updating the sysjobs. I had the same issue when i was running a
query against sysjobschedules to reset the active start time . Any
suggestions are appreciable
Regards
SwamiDont know what you did to SysJobs for this, but you probably need to go to
each job and delete the entry from the notifications tab.
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:FB94A9AA-62EE-402C-9A2F-9399A30724F9@.microsoft.com...
> Hi
> I run a query against sysjobs table to turn off the email notification,
> but
> still i am getting notification from jobs. Do I need to update any other
> table while updating the sysjobs. I had the same issue when i was
> running a
> query against sysjobschedules to reset the active start time . Any
> suggestions are appreciable
> Regards
> Swami

Email Notification

Hi
I run a query against sysjobs table to turn off the email notification, but
still i am getting notification from jobs. Do I need to update any other
table while updating the sysjobs. I had the same issue when i was running a
query against sysjobschedules to reset the active start time . Any
suggestions are appreciable
Regards
Swami
Dont know what you did to SysJobs for this, but you probably need to go to
each job and delete the entry from the notifications tab.
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:FB94A9AA-62EE-402C-9A2F-9399A30724F9@.microsoft.com...
> Hi
> I run a query against sysjobs table to turn off the email notification,
> but
> still i am getting notification from jobs. Do I need to update any other
> table while updating the sysjobs. I had the same issue when i was
> running a
> query against sysjobschedules to reset the active start time . Any
> suggestions are appreciable
> Regards
> Swami

Email Notification

Hi
I run a query against sysjobs table to turn off the email notification, but
still i am getting notification from jobs. Do I need to update any other
table while updating the sysjobs. I had the same issue when i was running
a
query against sysjobschedules to reset the active start time . Any
suggestions are appreciable
Regards
SwamiDont know what you did to SysJobs for this, but you probably need to go to
each job and delete the entry from the notifications tab.
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:FB94A9AA-62EE-402C-9A2F-9399A30724F9@.microsoft.com...
> Hi
> I run a query against sysjobs table to turn off the email notification,
> but
> still i am getting notification from jobs. Do I need to update any other
> table while updating the sysjobs. I had the same issue when i was
> running a
> query against sysjobschedules to reset the active start time . Any
> suggestions are appreciable
> Regards
> Swami

Email ID Validation in SQL Query

Hi,
Can someone help me with a query to validate if a value stored in the
emailaddress field in a table is a valid email id or no. Please mail me
ASAP. Thanks in advance.
Regards
DineshDinesh
I'm not sure iunderstood your question.
Since you have not provided a table structure along with sample data , I
guess you can do something like that
IF EXISTS (SELECT * FROM Table WHERE email_id=@.par)
--do soemthing
ELSE
--do somethimg else
"Dinesh" <Dinesh@.discussions.microsoft.com> wrote in message
news:80CE816E-A91C-4ECE-93E4-19006167B567@.microsoft.com...
> Hi,
> Can someone help me with a query to validate if a value stored in the
> emailaddress field in a table is a valid email id or no. Please mail me
> ASAP. Thanks in advance.
> Regards
> Dinesh|||Dinesh skrev:

> Hi,
> Can someone help me with a query to validate if a value stored in the
> emailaddress field in a table is a valid email id or no. Please mail me
> ASAP. Thanks in advance.
> Regards
> Dinesh
Depends on what you actually want to validate...
Is it only that the value looks like 'somename@.someaddress', or is it
to check if there really IS such an (active?) email account, or is it
to check against a table with valid email addresses? Or something else?
/impslayer, aka Birger Johansson|||Please explain in detail, your question? Mean provide sample data situation
Thanks,
Siva
"impslayer" wrote:

> Dinesh skrev:
>
> Depends on what you actually want to validate...
> Is it only that the value looks like 'somename@.someaddress', or is it
> to check if there really IS such an (active?) email account, or is it
> to check against a table with valid email addresses? Or something else?
> /impslayer, aka Birger Johansson
>

Sunday, March 11, 2012

email details from SQL Server agent based on query results?

Hello,

I want to remove records from the database automatically, BUT it is very important for me to know (email) if there were records or not and how many are affected by the automatic task...

My job is scheduled to run every day and does something like:

DELETE from RadioactiveMaterials

WHERE (NotExplosive = true)

SET @.rowcount_var = @.@.ROWCOUNT

I would like to get detail on the deleted records, how can I produce the email?

If you are using SQL 2005, using Books Online, refer to the Topic: 'Database Mail How-to Topics'.

If you are using SQL 2000, I suggest that you check out xp_smtp_mail from here. Most folks will recommend NOT to use MAPI mail on a SQL Server.

|||

Arnie Rowland wrote:

If you are using SQL 2005, using Books Online, refer to the Topic: 'Database Mail How-to Topics'.

Database Mail How-to Topics:

http://msdn2.microsoft.com/en-us/library/ms188298.aspx

Paul A. Mestemaker II

Program Manager

Microsoft SQL Server Manageability

http://blogs.msdn.com/sqlrem/

Friday, March 9, 2012

email address domain strip of query

Could this query be made more efficient?
It takes ages to run it. It strips of everything from an email address and keeps only the domain.

SUBSTRING(Mailaddress, CHARINDEX('@.', Mailaddress) + 1, CHARINDEX('.', SUBSTRING(Mailaddress, CHARINDEX('@.', Mailaddress) + 1, 100)) - 1) AS mail_domaingot 2005? string manipulation is faster in CLR.|||unfortunately no i don't. I may upgrade soon but for now it is 2000 im using.|||I assume that if you take this column out of the select list, the plan remains the same, but the query time goes up? Does the query time remain the same when you add the raw email address to the select list (and comment out all the substringing)? I am wondering, if you accidentally got a covering index on all of the fields not associated with the email addresses, or maybe the query is using different indexes for the query with all the substrings.

Also, not to be a nit picker, but which part of the domain are you after? An email address can be very complex. My brother has an email address that ends in @.haystack.mit.edu. Some of our British posters would have addresses like @.company.co.uk. I am guessing you would be interested in the "mit" or the "company", but not in "co' or "haystack".|||yes its from select list and no joins so it should be very fast. I se now that i have to make this to work with thoose split domain names aswell... damn :)

My question about the query was more kinda of " is this a stupid way to do this"?
i can live with the time it takes to run this query it is after al quite a large table.

thx for your help

Wednesday, March 7, 2012

EM query strange behavior

In the Enterprise Manager query tool, a query (the date entered in the
criteria field as 31.03.05) displays as an SQL statement:
SELECT *
FROM [TABLE]
WHERE (TRANS_DATE > CONVERT(DATETIME, '2005-03-31 00:00:00', 102))
and yields the expected results.
However, changing query type to
DELETE FROM [SAME TABLE AS ABOVE]
WHERE (TRANS_DATE > CONVERT(DATETIME, '2005-03-31 00:00:00', 102))
results in the opposite of what is to be expected - all records where
TRANS_DATE < [the entered time] is deleted.
The TRANS_DATE field is of type DATETIME, and I cannot see that there are
any properties either in the field or the table that separates it from all
my other DATETIME fields in any other tables, where this bizarre delete
action does not occur.
I assume this has to do with some configuration of the automatic
timeconversion that happens in the tool itself, but how to change this
conversion setting so as to produce more desired delete results?
And how is it that it only happens with data from one single table'
Thanks for answering.
Message posted via http://www.droptable.comHi
What happens when you run this:
DELETE FROM [SAME TABLE AS ABOVE]
WHERE (TRANS_DATE > '2005-03-31 00:00:00'
Regards
Mike
"Knut Bohn via droptable.com" wrote:

> In the Enterprise Manager query tool, a query (the date entered in the
> criteria field as 31.03.05) displays as an SQL statement:
> SELECT *
> FROM [TABLE]
> WHERE (TRANS_DATE > CONVERT(DATETIME, '2005-03-31 00:00:00', 102))
> and yields the expected results.
> However, changing query type to
> DELETE FROM [SAME TABLE AS ABOVE]
> WHERE (TRANS_DATE > CONVERT(DATETIME, '2005-03-31 00:00:00', 102))
> results in the opposite of what is to be expected - all records where
> TRANS_DATE < [the entered time] is deleted.
> The TRANS_DATE field is of type DATETIME, and I cannot see that there are
> any properties either in the field or the table that separates it from all
> my other DATETIME fields in any other tables, where this bizarre delete
> action does not occur.
> I assume this has to do with some configuration of the automatic
> timeconversion that happens in the tool itself, but how to change this
> conversion setting so as to produce more desired delete results?
> And how is it that it only happens with data from one single table'
> Thanks for answering.
> --
> Message posted via http://www.droptable.com
>|||Knut
I dont uderstand you.
> In the Enterprise Manager query tool, a query (the date entered in the
> criteria field as 31.03.05) displays as an SQL statement:
You said that the table's column is defined as datetime datatype and data
was entered as 31.03.05 which is thrown the error
--insert into table1 values ('31.03.05')
"The conversion of a char data type to a datetime data type resulted in an
out-of-range datetime value.
The statement has been terminated."
"Knut Bohn via droptable.com" <forum@.nospam.droptable.com> wrote in
message news:b10f4c5d93df49c6b3c31bee2a957db0@.SQ
droptable.com...
> In the Enterprise Manager query tool, a query (the date entered in the
> criteria field as 31.03.05) displays as an SQL statement:
> SELECT *
> FROM [TABLE]
> WHERE (TRANS_DATE > CONVERT(DATETIME, '2005-03-31 00:00:00', 102))
> and yields the expected results.
> However, changing query type to
> DELETE FROM [SAME TABLE AS ABOVE]
> WHERE (TRANS_DATE > CONVERT(DATETIME, '2005-03-31 00:00:00', 102))
> results in the opposite of what is to be expected - all records where
> TRANS_DATE < [the entered time] is deleted.
> The TRANS_DATE field is of type DATETIME, and I cannot see that there are
> any properties either in the field or the table that separates it from all
> my other DATETIME fields in any other tables, where this bizarre delete
> action does not occur.
> I assume this has to do with some configuration of the automatic
> timeconversion that happens in the tool itself, but how to change this
> conversion setting so as to produce more desired delete results?
> And how is it that it only happens with data from one single table'
> Thanks for answering.
> --
> Message posted via http://www.droptable.com|||Mike;
Same thing - deletes records with TRANS_DATE < entered value.
What's really bizzarre is that there's another datetime column in the
table, and running a delete with criteria filtered against those date
values yields the expected result.
Again, I really can't spot any differences in the respective data
properties of these two columns.
Uri;
I don't think I follow what you're getting at? The SELECT runs fine with
the date criteria entered as 31.03.05, but somehow things go off
differently with no other change thatn replacing SELECT with DELETE.
Message posted via http://www.droptable.com|||Hi
I did some test
CREATE TABLE #Test
(
col DATETIME
)
INSERT INTO #Test VALUES ('20050331')--Proper format to insert datetime
INSERT INTO #Test VALUES ('20050401')
INSERT INTO #Test VALUES ('20050328')
DELETE FROM #Test WHERE col>'20050331'--Deletes 1 row
SELECT* FROM #Test--Everything is ok
DROP TABLE #Test
--Another repro
CREATE TABLE #Test
(
col VARCHAR(30)
)
INSERT INTO #Test VALUES ('31.03.05')--with datetime this insert will be
failed
INSERT INTO #Test VALUES ('28.03.05')--with datetime this insert will be
failed
INSERT INTO #Test VALUES ('01.04.05')--with datetime this insert will be
failed
DELETE FROM #Test WHERE col>CONVERT(DATETIME,'2005-03-31',102)--Error is
thrown
SELECT CONVERT(DATETIME,REPLACE(col,'.',''),102) FROM #Test
--2031-03-05 00:00:00.000
--2028-03-05 00:00:00.000
--2001-04-05 00:00:00.000
--That's why it deletes wrong data
DELETE FROM #Test WHERE CONVERT(DATETIME,REPLACE(col,'.',''),112)
>CONVERT(DATETIME,'2005-03-31',102)
SELECT* FROM #Test
DROP TABLE #Test
"Knut Bohn via droptable.com" <forum@.droptable.com> wrote in message
news:c446a5e8529b4bc49709d20ca6d2518d@.SQ
droptable.com...
> Mike;
> Same thing - deletes records with TRANS_DATE < entered value.
> What's really bizzarre is that there's another datetime column in the
> table, and running a delete with criteria filtered against those date
> values yields the expected result.
> Again, I really can't spot any differences in the respective data
> properties of these two columns.
> Uri;
> I don't think I follow what you're getting at? The SELECT runs fine with
> the date criteria entered as 31.03.05, but somehow things go off
> differently with no other change thatn replacing SELECT with DELETE.
> --
> Message posted via http://www.droptable.com|||Uri,
Thaanks for taking the time to test this. However, I don't think it
explains the criteria oddity that occurs when in the query changing from
SELECT to DELETE?
best,
knut
Message posted via http://www.droptable.com