| Author |
Topic |
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2011-10-31 : 20:36:41
|
| ihve got a project in vs 2010, en ive got a list of items to chose an option from a dropdownlistexampleinformation )do you have options (dropdownlist)1. grandfather 0 1 2 2. grandmother 0 1 2 (send button)this is an exampleif i choose1. grandfather 02. grandmother 2in my table of my database sql server 2008 the information will save thiscolumnid item selection1 grandfather 02 grandmother 2but i need your help because i want that if i choose the option(0) in dropdownlist the information wont be save in the table , like thiscolumnid item selection1 grandmother 2could you help me to do some restriction ( now th egranfather item doesnt appearthanks a lot |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2011-11-01 : 10:43:21
|
| 1. State the questionif i insert a specific string 'Na' in a specific row in a table ; how can i do to dont save that information ?? 2. Please post the DDL of your tables (Including Indexes, and constraints)CREATE TABLE [dbo].[example1]( [id] [int] IDENTITY(1,1) NOT NULL, [item] [varchar](50) NULL, [selection] [varchar](50) NULL) ON [PRIMARY]GOGO3. Post some sample data in the form of DML " the selection values come from a asp.net code a drop down list with this options ('na', 'excellent', 'good, 'bad')INSERT INTO example1(item , selection) VALUES ('door', 'excellent')INSERT INTO example1(item , selection) VALUES ('bed', 'good')INSERT INTO example1(item , selection) VALUES ('bath', 'na')currently ive got this in my table example1select * from example1id item selection1 door excellent2 bed good3 bath na----5. Post the expected resultsbut id like when the selection ='na' the entire data row wont be savedlike this ( row number 3 doesnt appear , beacuse selection = 'na'select * from example1id item selection1 door excellent2 bed goodhow can i do thati really need your help, thanks in advanced |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-01 : 11:40:52
|
sounds like thisdeclare @yourstring varchar(100)set @yourstring = 'na'select * from example1 where selection <> @yourstring ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2011-11-01 : 11:56:54
|
| i get what you say, but I want is to have a clause that does not allow information to be saved if i try to insert in a selection = 'na', that if I run an insert where selection = 'na' the insert statement is not completed and continue to the next itemexample INSERT INTO example1(item , selection) VALUES ('door', 'excellent')INSERT INTO example1(item , selection) VALUES ('bed', 'na')INSERT INTO example1(item , selection) VALUES ('bath', 'na')INSERT INTO example1(item , selection) VALUES ('spoon', 'good')id like my result be this ( bath 'na' and bed 'na' dont exist , didnt be saved) id item selection1 door excellent2 spoon good thanks in advanced, you are very patient and kind |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-01 : 12:00:13
|
oh ok. then what you want is instead of insert trigger like thisCREATE TRIGGER InsertValidate_triggerON example1INSTEAD OF INSERTASBEGININSERT INTO example1SELECT columnsFROM INSERTEDWHERE selection <> 'na'END ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2011-11-01 : 12:21:01
|
| hi i paste the query and executeCREATE TRIGGER InsertValidate_triggerON example1INSTEAD OF INSERTASBEGININSERT INTO example1SELECT columnsFROM INSERTEDWHERE selection <> 'na'ENDand i have these errorsMsg 207, Level 16, State 1, Procedure InsertValidate_trigger, Line 7Invalid column name 'columns'.Msg 213, Level 16, State 1, Procedure InsertValidate_trigger, Line 6Column name or number of supplied values does not match table definitionim sorry im a really amateur on sql, could you say me whats wrong?thanks again |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-01 : 12:23:20
|
quote: Originally posted by sebastian11c hi i paste the query and executeCREATE TRIGGER InsertValidate_triggerON example1INSTEAD OF INSERTASBEGININSERT INTO example1SELECT columnsFROM INSERTEDWHERE selection <> 'na'ENDand i have these errorsMsg 207, Level 16, State 1, Procedure InsertValidate_trigger, Line 7Invalid column name 'columns'.Msg 213, Level 16, State 1, Procedure InsertValidate_trigger, Line 6Column name or number of supplied values does not match table definitionim sorry im a really amateur on sql, could you say me whats wrong?thanks again
you need to put actual column names there. i just put a place holder there for you as I dont know full columns present in yourtable------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2011-11-01 : 12:36:06
|
| ooo that works you are a genius thanks a lot |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-01 : 12:37:47
|
quote: Originally posted by sebastian11c ooo that works you are a genius thanks a lot
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-11-01 : 13:37:38
|
| Depending on your goal it might make more sense to put a check constraint on that column. |
 |
|
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2011-11-01 : 14:24:18
|
| hi lamprey, im interested in everything i could learn,could you explain to me what are you talking about check constarint and give me an examplei ll really apreciate your help |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-01 : 14:39:41
|
quote: Originally posted by sebastian11c hi lamprey, im interested in everything i could learn,could you explain to me what are you talking about check constarint and give me an examplei ll really apreciate your help
what he was suggesting was something like thisALTER TABLE example1 ADD CONSTRAINT Chk_Data CHECK( selection <> 'na') it will also avoid addition of any data with na value in selection------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2011-11-01 : 15:00:34
|
| well done again visakh16thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-02 : 05:45:25
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2011-11-03 : 09:41:18
|
| hi visakh16 i need youur help one more time, 1. State the questionI have to update a table based on a weekly excel file how can i update the table without inserting duplicate information and updating the state if the info exist in the table and doesnt exist anymore in the excel file ??i know , the first step is impot the excel file to a table in sql please follow the example below2. Please post the DDL of your tables **principal tableCREATE TABLE [dbo].[bill]( [idbill] [int] NULL, [name] [nchar](10) NULL, [debt] [int] NULL, [state] [varchar](50) NULL) ON [PRIMARY]GOEXAMPLEIN MY PRINCIPAL TABLE IVE GOT THISidbill name debt State11 peter 1000 open16 samanta 1200 open18 nicolas 800 open23 jhon 200 open32 sean 5000 openFOR EXAMPLE , IN MY WEEKLY EXCEL IMPORT TABLE , IVE GOT THIS(check that nicolas and sean dont appear anymore, and have 3 new rows (arnold, andy , michael)idbill name debt state11 peter 1000 open16 samanta 1200 open23 jhon 200 open33 ARNOLD 10000 open47 andy 7000 open53 michael 3000 openExpécted ResultI NEED MY PRINCIPAL TABLE UPATED THIS WAYidbill name debt state11 peter 1000 open16 samanta 1200 open18 nicolas 800 CLOSED23 jhon 200 open32 sean 5000 CLOSED33 ARNOLD 10000 open47 andy 7000 open53 michael 3000 openTHAT MEANS I NEED TO INSERT NEW DATA IN MY PRINCIPAL TABLE FROM MY WEEKLY EXCEL TABLE WITHOUT DUPLICATE INFORMATION, AND I NEED TO UPDATE THE STATE IN MY PRINCIPAL TABLE FROM TTHE WEEKLY EXCEL TABLE OF THE INFO THAT DONT APPEAR ANYMORE ( LIKE NICOLAS AND SEAN WHICH STATE WAS UPDATED FROM OPEN TO CLOSED)THESE ARE AN EXAMPLE TABLE BUT MY REAL TABLES HAVE SEVERAL ROWS THOUSANDS of themim thinking running a loop statement , but i dont know how to do itor any other idea its coolyour help will be appreciatedthanks in advanced |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2011-11-03 : 10:52:53
|
| hi its simple to import excel tables to sql with export and import data in sql server 2008 r2, ive already donemy problem is,EXAMPLEIN MY PRINCIPAL TABLE "bills" IVE GOT THIS (this is an existing table in sql )idbill name debt State11 peter 1000 open16 samanta 1200 open18 nicolas 800 open23 jhon 200 open32 sean 5000 openFOR EXAMPLE , IN MY WEEKLY EXCEL IMPORT TABLE "weekly" ( ive alreadi imported to sql), IVE GOT THIS(check that nicolas and sean dont appear anymore, and have 3 new rows (arnold, andy , michael)idbill name debt state11 peter 1000 open16 samanta 1200 open23 jhon 200 open33 ARNOLD 10000 open47 andy 7000 open53 michael 3000 openExpécted ResultI NEED MY PRINCIPAL TABLE "bills" UPATED THIS WAYidbill name debt state11 peter 1000 open16 samanta 1200 open18 nicolas 800 CLOSED23 jhon 200 open32 sean 5000 CLOSED33 ARNOLD 10000 open47 andy 7000 open53 michael 3000 openTHAT MEANS I NEED TO INSERT NEW DATA IN MY PRINCIPAL TABLE "bills" FROM MY WEEKLY EXCEL TABLE "weekly" WITHOUT DUPLICATE INFORMATION, AND I NEED TO UPDATE THE STATE IN MY PRINCIPAL TABLE FROM THE TABLE "weekly" OF THE INFO THAT DONT APPEAR ANYMORE ( LIKE NICOLAS AND SEAN WHICH STATE WAS UPDATED FROM OPEN TO CLOSED)THESE ARE AN EXAMPLE TABLE BUT MY REAL TABLES HAVE SEVERAL ROWS THOUSANDS of themim thinking running a loop statement , but i dont know how to do itor any other idea its coolyour help will be appreciatedthanks in advanced |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-03 : 11:01:44
|
| nope. just use OPENROWSET and excel will be considered like a tablethen you can use LEFT JOIN and check for NULLs to identify new data and INNER JOIN to identify existing data------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2011-11-03 : 11:25:25
|
| lets put in other wayi have 2 differents tables "bill" and "Check" i need to compare these 2 tables and update one of them and thats what i needEXAMPLEtable "bill" ( columns : idbill, name, debt, state) idbill name debt State11 peter 1000 open16 samanta 1200 open18 nicolas 800 open23 jhon 200 open32 Sean 5000 openand the other table "Check" ( columns : idbill, name, debt, state)(check that nicolas and sean dont appear anymore, and have 3 new rows (arnold, andy , michael)idbill name debt state11 peter 1000 open16 samanta 1200 open23 jhon 200 open33 ARNOLD 10000 open47 andy 7000 open53 michael 3000 openExpécted Resultafter comparing 2 tables i need the TABLE "bill" will be UPATED THIS WAYidbill name debt state11 peter 1000 open16 samanta 1200 open18 nicolas 800 CLOSED23 jhon 200 open32 sean 5000 CLOSED33 ARNOLD 10000 open47 andy 7000 open53 michael 3000 openTHAT MEANS I NEED TO INSERT NEW DATA IN TABLE "bill" FROM TABLE "Check" WITHOUT DUPLICATE INFORMATION, AND I NEED TO UPDATE THE STATE IN MY TABLE "bill" FROM THE TABLE "Check" OF THE INFO THAT DONT APPEAR ANYMORE ( LIKE NICOLAS AND SEAN WHICH STATE WAS UPDATED FROM OPEN TO CLOSED in table "bill")THESE ARE AN EXAMPLE TABLE BUT MY REAL TABLES HAVE SEVERAL ROWS THOUSANDS of themim thinking running a loop statement , but i dont know how to do itor any other idea its coolyour help will be appreciatedthanks in advancedsorry if im not very clearthanks again |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-03 : 11:47:52
|
| [code]insert into billselect c.columns...from check cleft join bill bon b.idbill = c.idbillwhere b.idbill is nullupdate bset b.state='closed'from bill b left join check con c.idbill = b.idbillwhere c.idbill is null[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Next Page
|