I want to restrict the results of a query only where the field 'email' has
something in it. I had a record with data in 'email' and deleted it and my
query still returns the record even thoug part of my statements reads:
Select * from Users
Where email is NOT NULL OR email <> ''
Even though I deleted what was in the 'email' field I still get the
recordset and the email field is blank.
Any clues ?
AleksHow can we reproduce the problem?
Please provide DDL and sample data.
http://www.aspfaq.com/etiquette.asp?id=5006
AMB
"Aleks" wrote:
> I want to restrict the results of a query only where the field 'email' has
> something in it. I had a record with data in 'email' and deleted it and my
> query still returns the record even thoug part of my statements reads:
> Select * from Users
> Where email is NOT NULL OR email <> ''
> Even though I deleted what was in the 'email' field I still get the
> recordset and the email field is blank.
> Any clues ?
> Aleks
>
>|||Aleks wrote:
> I want to restrict the results of a query only where the field
> 'email' has something in it. I had a record with data in 'email' and
> deleted it and my query still returns the record even thoug part of
> my statements reads:
> Select * from Users
> Where email is NOT NULL OR email <> ''
> Even though I deleted what was in the 'email' field I still get the
> recordset and the email field is blank.
>
Change "OR" to "AND".
When you deleted the contents, you likely did not set the field to Null, so
"email is NOT NULL" evaluates to True, resulting in the OR expression
evaluating to True.
Better yet, do something like this:
Where email > CHAR(1)
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Showing posts with label email. Show all posts
Showing posts with label email. Show all posts
Wednesday, March 28, 2012
Monday, March 26, 2012
Query Problem
This has to be obvious but I can't see the problem. I am executing the
query:
=======================================
Insert Into TempTable (email) Values (Select Distinct N1.Email From Names N1
Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass In (
'A', 'AAA', 'AAAAA'))
=======================================
But I get a syntax error "near Select". Can someone straighten me out.
Thanks
WayneTry this
Insert Into TempTable (email) (Select Distinct N1.Email From Names N1
Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass
In (
'A', 'AAA', 'AAAAA'))
Madhivanan|||Take out the VALUES keyword. You do not, and actually cannot, include that
keyword when performing an INSERT ... SELECT.
Richard
"Wayne Wengert" wrote:
> This has to be obvious but I can't see the problem. I am executing the
> query:
> =======================================
> Insert Into TempTable (email) Values (Select Distinct N1.Email From Names
N1
> Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass In (
> 'A', 'AAA', 'AAAAA'))
> =======================================
>
> But I get a syntax error "near Select". Can someone straighten me out.
>
> Thanks
>
> Wayne
>
>|||This will do
Insert Into TempTable (email)
(Select Distinct N1.Email From Names N1
Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass In (
'A', 'AAA', 'AAAAA'))
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Wayne Wengert" <wayneDONTWANTSPAM@.wengert.com> wrote in message
news:u8lSldZHFHA.1176@.TK2MSFTNGP12.phx.gbl...
> This has to be obvious but I can't see the problem. I am executing the
> query:
> =======================================
> Insert Into TempTable (email) Values (Select Distinct N1.Email From Names
> N1
> Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass In (
> 'A', 'AAA', 'AAAAA'))
> =======================================
>
> But I get a syntax error "near Select". Can someone straighten me out.
>
> Thanks
>
> Wayne
>|||You can't have a SELECT statement in the values clause.
Is this statement intended to insert one row or multiple rows.
Madhivanan's solution works for 1 row. The following will insert as
many rows as returned by the query:
INSERT INTO TempTable (email)
SELECT DISTINCT N1.Email
FROM Names N1
INNER JOIN Bands B1
ON B1.BandDirector = N1.NameID
WHERE B1.BandClass In ('A', 'AAA', 'AAAAA')
David Portas
SQL Server MVP
--|||Thanks all. I didn't realize that you could not use "Values" in that case.
Wayne
"Wayne Wengert" <wayneDONTWANTSPAM@.wengert.com> wrote in message
news:u8lSldZHFHA.1176@.TK2MSFTNGP12.phx.gbl...
> This has to be obvious but I can't see the problem. I am executing the
> query:
> =======================================
> Insert Into TempTable (email) Values (Select Distinct N1.Email From Names
N1
> Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass In (
> 'A', 'AAA', 'AAAAA'))
> =======================================
>
> But I get a syntax error "near Select". Can someone straighten me out.
>
> Thanks
>
> Wayne
>
query:
=======================================
Insert Into TempTable (email) Values (Select Distinct N1.Email From Names N1
Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass In (
'A', 'AAA', 'AAAAA'))
=======================================
But I get a syntax error "near Select". Can someone straighten me out.
Thanks
WayneTry this
Insert Into TempTable (email) (Select Distinct N1.Email From Names N1
Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass
In (
'A', 'AAA', 'AAAAA'))
Madhivanan|||Take out the VALUES keyword. You do not, and actually cannot, include that
keyword when performing an INSERT ... SELECT.
Richard
"Wayne Wengert" wrote:
> This has to be obvious but I can't see the problem. I am executing the
> query:
> =======================================
> Insert Into TempTable (email) Values (Select Distinct N1.Email From Names
N1
> Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass In (
> 'A', 'AAA', 'AAAAA'))
> =======================================
>
> But I get a syntax error "near Select". Can someone straighten me out.
>
> Thanks
>
> Wayne
>
>|||This will do
Insert Into TempTable (email)
(Select Distinct N1.Email From Names N1
Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass In (
'A', 'AAA', 'AAAAA'))
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Wayne Wengert" <wayneDONTWANTSPAM@.wengert.com> wrote in message
news:u8lSldZHFHA.1176@.TK2MSFTNGP12.phx.gbl...
> This has to be obvious but I can't see the problem. I am executing the
> query:
> =======================================
> Insert Into TempTable (email) Values (Select Distinct N1.Email From Names
> N1
> Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass In (
> 'A', 'AAA', 'AAAAA'))
> =======================================
>
> But I get a syntax error "near Select". Can someone straighten me out.
>
> Thanks
>
> Wayne
>|||You can't have a SELECT statement in the values clause.
Is this statement intended to insert one row or multiple rows.
Madhivanan's solution works for 1 row. The following will insert as
many rows as returned by the query:
INSERT INTO TempTable (email)
SELECT DISTINCT N1.Email
FROM Names N1
INNER JOIN Bands B1
ON B1.BandDirector = N1.NameID
WHERE B1.BandClass In ('A', 'AAA', 'AAAAA')
David Portas
SQL Server MVP
--|||Thanks all. I didn't realize that you could not use "Values" in that case.
Wayne
"Wayne Wengert" <wayneDONTWANTSPAM@.wengert.com> wrote in message
news:u8lSldZHFHA.1176@.TK2MSFTNGP12.phx.gbl...
> This has to be obvious but I can't see the problem. I am executing the
> query:
> =======================================
> Insert Into TempTable (email) Values (Select Distinct N1.Email From Names
N1
> Inner Join Bands B1 On B1.BandDirector = N1.NameID Where B1.BandClass In (
> 'A', 'AAA', 'AAAAA'))
> =======================================
>
> But I get a syntax error "near Select". Can someone straighten me out.
>
> Thanks
>
> Wayne
>
Friday, March 23, 2012
query plan
I ran a sql query plan on query analizer, I need to send to someone by
email.
How do I send a query plan?
Thanksyou can take a snapshot of the query using "Print Screen"
button of the keyboard and generating bmp file out of it.
note: you will have an option to zoom in and zoom out the
image of "graphical query plan". you will get this by
right clicking on the "execution plan" pane.
Or you can send the textual outupt of the "query plan" by
turning on the option "SHOWPLAN_ALL". And the generated
output can be saved in TEXT file.
Ex:
USE pubs
GO
SET SHOWPLAN_ALL ON
GO
SELECT au_id
FROM authors
WHERE au_id = '409-56-7008'
GO
- Vishal
>--Original Message--
>I ran a sql query plan on query analizer, I need to send
to someone by
>email.
>How do I send a query plan?
>Thanks
>
>.
>sql
email.
How do I send a query plan?
Thanksyou can take a snapshot of the query using "Print Screen"
button of the keyboard and generating bmp file out of it.
note: you will have an option to zoom in and zoom out the
image of "graphical query plan". you will get this by
right clicking on the "execution plan" pane.
Or you can send the textual outupt of the "query plan" by
turning on the option "SHOWPLAN_ALL". And the generated
output can be saved in TEXT file.
Ex:
USE pubs
GO
SET SHOWPLAN_ALL ON
GO
SELECT au_id
FROM authors
WHERE au_id = '409-56-7008'
GO
- Vishal
>--Original Message--
>I ran a sql query plan on query analizer, I need to send
to someone by
>email.
>How do I send a query plan?
>Thanks
>
>.
>sql
Subscribe to:
Posts (Atom)