A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

how to insert a where clause in Insert Into... statement?



 
 
Thread Tools Display Modes
  #1  
Old December 9th, 2004, 10:32 AM
external usenet poster
 
Posts: n/a
Default how to insert a where clause in Insert Into... statement?

how to insert a where clause in Insert Into... statement
  #2  
Old December 9th, 2004, 12:02 PM
Michel Walsh
external usenet poster
 
Posts: n/a
Default

Hi,



What you are inserting starts with a standard SELECT ... which can
have the standard WHERE clause.

Note that the WHERE clause is applied to limit what you inserted, not to
specify a position of the insertion has to be done, since tables do not have
"position" (for their records). Rercordsets have a position (move next, move
previous), but tables don't.



Hoping it may help,
Vanderghast, Access MVP



wrote in message
...
how to insert a where clause in Insert Into... statement



  #3  
Old December 9th, 2004, 12:06 PM
Allen Browne
external usenet poster
 
Posts: n/a
Default

In what context?

In code, you might store the stub of of the statement (up to the Where
clause) and any tail (after the Where clause) as two separate strings, and
insert your WHERE clause at runtime.

Function DoAnUpdate()
Dim strSql As String
Const strcStub = "INSERT ..."
Const strcTail = "ORDER BY MyField;"

strSql = strcStub & " WHERE SomeField = """ & Me.SomeTextbox & """ " &
strcTail
dbEngine(0)(0).Execute strSql, dbFailOnError

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

wrote in message
...
how to insert a where clause in Insert Into... statement



  #4  
Old December 9th, 2004, 12:56 PM
external usenet poster
 
Posts: n/a
Default

thanx Allen,
actually i have a table with some datas, i want to insert
some more datas in that table through an append query,
but i want that new datas should come with the old data
like:
field1 of table(prev)data abcd & field2 is blank but
after running the append query field1 data abcd field2
data 1234.
how to do that??

-----Original Message-----
In what context?

In code, you might store the stub of of the statement

(up to the Where
clause) and any tail (after the Where clause) as two

separate strings, and
insert your WHERE clause at runtime.

Function DoAnUpdate()
Dim strSql As String
Const strcStub = "INSERT ..."
Const strcTail = "ORDER BY MyField;"

strSql = strcStub & " WHERE SomeField = """ &

Me.SomeTextbox & """ " &
strcTail
dbEngine(0)(0).Execute strSql, dbFailOnError

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

wrote in message
...
how to insert a where clause in Insert Into...

statement


.

  #5  
Old December 9th, 2004, 03:28 PM
Allen Browne
external usenet poster
 
Posts: n/a
Default

So you want some records to update, and others to append?

You will need to execute 2 queries: one for the INSERT, and one for the
UPDATE.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

wrote in message
...
thanx Allen,
actually i have a table with some datas, i want to insert
some more datas in that table through an append query,
but i want that new datas should come with the old data
like:
field1 of table(prev)data abcd & field2 is blank but
after running the append query field1 data abcd field2
data 1234.
how to do that??

-----Original Message-----
In what context?

In code, you might store the stub of of the statement

(up to the Where
clause) and any tail (after the Where clause) as two

separate strings, and
insert your WHERE clause at runtime.

Function DoAnUpdate()
Dim strSql As String
Const strcStub = "INSERT ..."
Const strcTail = "ORDER BY MyField;"

strSql = strcStub & " WHERE SomeField = """ &

Me.SomeTextbox & """ " &
strcTail
dbEngine(0)(0).Execute strSql, dbFailOnError

wrote in message
...
how to insert a where clause in Insert Into...

statement



  #6  
Old December 9th, 2004, 03:37 PM
Michel Walsh
external usenet poster
 
Posts: n/a
Default

Hi,


An append-update is doable in Jet (not in MS SQL Server):


UPDATE oldInventory As o RIGHT JOIN newList As n
ON o.ItemID = n.ItemID
SET o.ItemID = n.ItemID,
o.UnitPrice= n.UnitPrice,
o.whatever = n.whatever



After the update, the oldinventory will got the new price, for existing
data, and will also got the brand new items in newList but not previously in
oldInventory. In MS SQL Server, you have to do two queries: one update (with
an inner join instead of the outer join illustrated here), and one insert
query to insert the new stuff).

Hoping it may help,
Vanderghast, Access MVP



wrote in message
...
thanx Allen,
actually i have a table with some datas, i want to insert
some more datas in that table through an append query,
but i want that new datas should come with the old data
like:
field1 of table(prev)data abcd & field2 is blank but
after running the append query field1 data abcd field2
data 1234.
how to do that??

-----Original Message-----
In what context?

In code, you might store the stub of of the statement

(up to the Where
clause) and any tail (after the Where clause) as two

separate strings, and
insert your WHERE clause at runtime.

Function DoAnUpdate()
Dim strSql As String
Const strcStub = "INSERT ..."
Const strcTail = "ORDER BY MyField;"

strSql = strcStub & " WHERE SomeField = """ &

Me.SomeTextbox & """ " &
strcTail
dbEngine(0)(0).Execute strSql, dbFailOnError

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

wrote in message
...
how to insert a where clause in Insert Into...

statement


.



  #7  
Old December 9th, 2004, 04:01 PM
Allen Browne
external usenet poster
 
Posts: n/a
Default

Michel, that's a wild idea. I like it.

Does not seem to work if ItemID is an AutoNumber though.
JET complains that the autonum field is not updatable.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Michel Walsh" vanderghast@VirusAreFunnierThanSpam wrote in message
...
Hi,

An append-update is doable in Jet (not in MS SQL Server):

UPDATE oldInventory As o RIGHT JOIN newList As n
ON o.ItemID = n.ItemID
SET o.ItemID = n.ItemID,
o.UnitPrice= n.UnitPrice,
o.whatever = n.whatever

After the update, the oldinventory will got the new price, for existing
data, and will also got the brand new items in newList but not previously
in oldInventory. In MS SQL Server, you have to do two queries: one update
(with an inner join instead of the outer join illustrated here), and one
insert query to insert the new stuff).

Hoping it may help,
Vanderghast, Access MVP



  #8  
Old December 9th, 2004, 05:55 PM
Michel Walsh
external usenet poster
 
Posts: n/a
Default

Hi Allen,


Indeed, if an autonumber is used, in old inventory, to validate the
"key", that creates a problem in that case.



Vanderghast, Access MVP


"Allen Browne" wrote in message
...
Michel, that's a wild idea. I like it.

Does not seem to work if ItemID is an AutoNumber though.
JET complains that the autonum field is not updatable.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.



  #9  
Old December 10th, 2004, 05:15 AM
external usenet poster
 
Posts: n/a
Default

Hi,
how to do it in SQL SERVER?? as i am trying to the data
present in SQL SERVER only.


-----Original Message-----
Hi,


An append-update is doable in Jet (not in MS SQL Server):


UPDATE oldInventory As o RIGHT JOIN newList As n
ON o.ItemID = n.ItemID
SET o.ItemID = n.ItemID,
o.UnitPrice= n.UnitPrice,
o.whatever = n.whatever



After the update, the oldinventory will got the new

price, for existing
data, and will also got the brand new items in newList

but not previously in
oldInventory. In MS SQL Server, you have to do two

queries: one update (with
an inner join instead of the outer join illustrated

here), and one insert
query to insert the new stuff).

Hoping it may help,
Vanderghast, Access MVP



wrote in message
...
thanx Allen,
actually i have a table with some datas, i want to

insert
some more datas in that table through an append query,
but i want that new datas should come with the old data
like:
field1 of table(prev)data abcd & field2 is blank but
after running the append query field1 data abcd field2
data 1234.
how to do that??

-----Original Message-----
In what context?

In code, you might store the stub of of the statement

(up to the Where
clause) and any tail (after the Where clause) as two

separate strings, and
insert your WHERE clause at runtime.

Function DoAnUpdate()
Dim strSql As String
Const strcStub = "INSERT ..."
Const strcTail = "ORDER BY MyField;"

strSql = strcStub & " WHERE SomeField = """ &

Me.SomeTextbox & """ " &
strcTail
dbEngine(0)(0).Execute strSql, dbFailOnError

--
Allen Browne - Microsoft MVP. Perth, Western

Australia.
Tips for Access users -

http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot

org.

wrote in message
.. .
how to insert a where clause in Insert Into...

statement


.



.

  #10  
Old December 10th, 2004, 11:27 AM
Michel Walsh
external usenet poster
 
Posts: n/a
Default

Hi,


You can update through a view (that makes the inner join ON itemID) or, if
you don't want to make a view just for that, you can still do (it is a
little bit different than with Jet):


UPDATE oldInventory
SET oldInventory.whatever= n.whatever
FROM newData As n
WHERE n.itemID=oldInventory.itemID




The insert is something that could look like:



INSERT INTO oldInventory(ItemID, field2, field3)
SELECT newData.ItemID, newData.field2, newData.field3
FROM newData LEFT JOIN oldInventory ON
newData.ItemID = oldInventory.itemID
WHERE oldInventory.ItemID IS NULL



Hoping it may help,
Vanderghast, Access MVP




wrote in message
...
Hi,
how to do it in SQL SERVER?? as i am trying to the data
present in SQL SERVER only.


-----Original Message-----
Hi,


An append-update is doable in Jet (not in MS SQL Server):


UPDATE oldInventory As o RIGHT JOIN newList As n
ON o.ItemID = n.ItemID
SET o.ItemID = n.ItemID,
o.UnitPrice= n.UnitPrice,
o.whatever = n.whatever



After the update, the oldinventory will got the new

price, for existing
data, and will also got the brand new items in newList

but not previously in
oldInventory. In MS SQL Server, you have to do two

queries: one update (with
an inner join instead of the outer join illustrated

here), and one insert
query to insert the new stuff).

Hoping it may help,
Vanderghast, Access MVP



wrote in message
...
thanx Allen,
actually i have a table with some datas, i want to

insert
some more datas in that table through an append query,
but i want that new datas should come with the old data
like:
field1 of table(prev)data abcd & field2 is blank but
after running the append query field1 data abcd field2
data 1234.
how to do that??

-----Original Message-----
In what context?

In code, you might store the stub of of the statement
(up to the Where
clause) and any tail (after the Where clause) as two
separate strings, and
insert your WHERE clause at runtime.

Function DoAnUpdate()
Dim strSql As String
Const strcStub = "INSERT ..."
Const strcTail = "ORDER BY MyField;"

strSql = strcStub & " WHERE SomeField = """ &
Me.SomeTextbox & """ " &
strcTail
dbEngine(0)(0).Execute strSql, dbFailOnError

--
Allen Browne - Microsoft MVP. Perth, Western

Australia.
Tips for Access users -

http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot

org.

wrote in message
. ..
how to insert a where clause in Insert Into...
statement


.



.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
INSERT statement problem ChrisP Running & Setting Up Queries 1 August 22nd, 2004 06:04 AM
Access 2000 query SQL statement into VBA code Clint Running & Setting Up Queries 1 June 10th, 2004 01:33 PM
Insert Syntax question for field names in the value portion of the command. Matthew Ferri New Users 1 June 7th, 2004 02:14 PM
Increment column value based on insert string A.W.J. Ales Worksheet Functions 1 April 15th, 2004 02:44 PM


All times are GMT +1. The time now is 05:32 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.