| Author |
Topic |
|
Denis McElligott
Starting Member
18 Posts |
Posted - 2006-03-21 : 08:47:45
|
| I am trying to put the following code in the view section but it tells me that only the "select function" can be used. How do I switch this to other functions?INSERT INTO Contact (Name, Address, PhoneNumber, DOB, PetsOwned)VALUES ('David Dog Dogowner', '10 Canine Drive', '(555) 743-8747', '5/7/1968', '4') |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-03-21 : 08:51:54
|
You can't have insert statement in View or UDF. You have to use Stored Procedure for this.What is your requirement ? KHChoice is an illusion, created between those with power, and those without.Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-03-21 : 08:52:01
|
| Why do you want to create view that insert records to a table?Give more details on what you are trying to doMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-03-21 : 08:53:44
|
| >>You can have insert statement in View or UDF.Did you mean "You can't have insert statement in View or UDF."?MadhivananFailing to plan is Planning to fail |
 |
|
|
Denis McElligott
Starting Member
18 Posts |
Posted - 2006-03-21 : 09:13:10
|
| To answer both of your questions, my requirement is to insert data into an existing database by using the insert function but Like I said in my first post, I received an eror message. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-03-21 : 09:16:47
|
You will get the error if you try to put that section of code in the create view statement.What are you trying to achieve ? KHChoice is an illusion, created between those with power, and those without.Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant |
 |
|
|
Denis McElligott
Starting Member
18 Posts |
Posted - 2006-03-21 : 09:18:18
|
| How do i use Stored Procedure for inserting statements in View or UDF? |
 |
|
|
Denis McElligott
Starting Member
18 Posts |
Posted - 2006-03-21 : 09:20:42
|
| I also have another question. It's about the Update function. For my database, I have to set the # of pets owned to 2 when a person's phone number has the number 6. How would I go about doing that? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-03-21 : 09:32:57
|
quote: Originally posted by Denis McElligott How do i use Stored Procedure for inserting statements in View or UDF?
create procedure your_procedure @Name varchar(50), @Address varchar(50), @PhoneNumber varchar(20), @DOB datetime, @PetsOwned intasbegin insert into Contact(Name, Address, PhoneNumber, DOB, PetsOwned) select @Name, @Address, @PhoneNumber, @DOB, @PetsOwnedend KHChoice is an illusion, created between those with power, and those without.Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-03-21 : 09:34:04
|
quote: How do i use Stored Procedure for inserting statements in View or UDF?
you can not inserted data into the UDF.. and for inserting data in the view also there are restrictions on that you can read the book online view for the same. what are you trying to acheive??do you mean that you want to insert the records using the select statements???then it will be somthing like these.. Insert <TableName> ( <ColumnName1>,<ColumnName2>...)Select ColumnName1>,<ColumnName2>... From TableName ??Please explain your case with some example.. database scripts.. etc.. so that we can help you in the better and faster way .. Hope this helps.Sucess Comes to those who Believe in Beauty of their Dream.. |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-03-21 : 09:36:14
|
quote: I also have another question. It's about the Update function. For my database, I have to set the # of pets owned to 2 when a person's phone number has the number 6. How would I go about doing that?
Somthing like this??Update <TableName> Set Pets = 2 Where PhoneNumber Like '%6%'Sucess Comes to those who Believe in Beauty of their Dream.. |
 |
|
|
Denis McElligott
Starting Member
18 Posts |
Posted - 2006-03-21 : 10:26:23
|
quote: Originally posted by chiragkhabaria
quote: How do i use Stored Procedure for inserting statements in View or UDF?
you can not inserted data into the UDF.. and for inserting data in the view also there are restrictions on that you can read the book online view for the same. what are you trying to acheive??do you mean that you want to insert the records using the select statements???then it will be somthing like these.. Insert <TableName> ( <ColumnName1>,<ColumnName2>...)Select ColumnName1>,<ColumnName2>... From TableName ??Please explain your case with some example.. database scripts.. etc.. so that we can help you in the better and faster way .. Hope this helps.Sucess Comes to those who Believe in Beauty of their Dream..
Here is what the table looks like:Name Address PhoneNumber DOB PetsOwnedJane Doe 90 River St. (987) 654-3210 1/1/1900 2 Mike Myers 100 Holbrook Rd. (781) 653-8942 9/7/1970 2 Doug Burnett 25 Vincent St. (203) 723-9851 10/1/1980 2Here is what I want the table to look like after I use the insert function- INSERT INTO Contact (Name, Address, PhoneNumber, DOB, PetsOwned)VALUES ('David Dogowner', '10 Canine Drive', '(555) 743-8747', '5/7/1968', '4'):Name Address PhoneNumber DOB PetsOwnedJane Doe 90 River St. (987) 654-3210 1/1/1900 2 Mike Myers 100 Holbrook Rd. (781) 653-8942 9/7/1970 2 Doug Burnett 25 Vincent St. (203) 723-9851 10/1/1980 2David Dogowner 10 Canine Drive (555) 743-8747 1/1/1900 4 When I go to put the code in, I go to "Views", then I right click and select "New View', then I paste the insert code that I made and thats where I am having problems. I'm sure that if I solve this problem, it will answer my question with the update function. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-03-21 : 10:36:34
|
where did you get the idea that you have to use views??views are used only to display data from n different tables that are joined in a n number of ways.they aren't meant for inserting data.insert statement is run either in stored procedure or by itself.Go with the flow & have fun! Else fight the flow |
 |
|
|
Denis McElligott
Starting Member
18 Posts |
Posted - 2006-03-21 : 10:45:10
|
quote: Originally posted by spirit1 where did you get the idea that you have to use views??views are used only to display data from n different tables that are joined in a n number of ways.they aren't meant for inserting data.insert statement is run either in stored procedure or by itself.Go with the flow & have fun! Else fight the flow 
stored procedure or by itself? How do I go about putting the insert statement in stored procedure or by itself? |
 |
|
|
Denis McElligott
Starting Member
18 Posts |
Posted - 2006-03-21 : 10:45:52
|
quote: Originally posted by spirit1 where did you get the idea that you have to use views??views are used only to display data from n different tables that are joined in a n number of ways.they aren't meant for inserting data.insert statement is run either in stored procedure or by itself.Go with the flow & have fun! Else fight the flow 
Do I do the same thing for the update statement? |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-03-21 : 10:53:22
|
yes. it's same for both.where are you executing these statements?if in Query Analyzer then just write it in the window and press F5 (run)khtan showed you how to write a stored procedure.Go with the flow & have fun! Else fight the flow |
 |
|
|
Denis McElligott
Starting Member
18 Posts |
Posted - 2006-03-21 : 11:02:44
|
| I went to stored procedure and put this code in:CREATE PROCEDURE [Insert] @Name varchar(50), @Address varchar(50), @PhoneNumber varchar(20), @DOB datetime, @PetsOwned intasbegin insert into Contact (David Dogowner, 10 Canine Drive, 555-743-8747, 5/7/1968, 4) select @Name, @Address, @PhoneNumber, @DOB, @PetsOwnedendwhen I clicked on "Ok", it said Error 170: Line 9: Incorrect Syntax near 'Dogowner'. I don't understand why it's saying that. |
 |
|
|
Denis McElligott
Starting Member
18 Posts |
Posted - 2006-03-21 : 11:04:01
|
quote: Originally posted by spirit1 yes. it's same for both.where are you executing these statements?if in Query Analyzer then just write it in the window and press F5 (run)khtan showed you how to write a stored procedure.Go with the flow & have fun! Else fight the flow 
I am executing these statements in Stored Procedure Properties. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-03-21 : 11:06:01
|
stored procedure proerties????whoa there!!!What are you using to access your sql server? Enterprise Manager, Query analyzer, something else?Go with the flow & have fun! Else fight the flow |
 |
|
|
jhermiz
3564 Posts |
Posted - 2006-03-21 : 11:24:01
|
Probably a good idea not to rush into this, pick up a good book and read about sql server and the tools associated with it.Don't get too caught up with trying to finish the project as fast as possible. You want to make sure you do a good job and have a good product, so take your time and do the research. Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url] |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-03-21 : 11:25:44
|
listen to him! he knows   Go with the flow & have fun! Else fight the flow |
 |
|
|
Next Page
|