November 1, 2012 at 8:37 am
i'm want insert some record in sql server. i try query but insert all record and value duplicate.
i need don't duplicate value and insert some record.
Table filesTA
runNo | cDate | cIn | cOut
00001| 2012-10-09 00:00:00.000| 2012-10-09 07:21:00.000| 2012-10-09 20:34:00.000
00005| 2012-10-09 00:00:00.000| 2012-10-09 07:36:00.000| 2012-10-09 17:04:00.000
00006| 2012-10-09 00:00:00.000| 2012-10-09 07:55:00.000|2012-10-09 20:34:00.000
00007| 2012-10-09 00:00:00.000| 2012-10-09 07:50:00.000| 2012-10-09 00:00:00.000
00008| 2012-10-09 00:00:00.000| 2012-10-09 07:56:00.000| 2012-10-09 20:35:00.000
00009| 2012-10-09 00:00:00.000| 2012-10-09 07:57:00.000|2012-10-09 20:32:00.000
00010| 2012-10-09 00:00:00.000| 2012-10-09 07:58:00.000| 2012-10-09 19:03:00.000
this code Stored Procedure
SELECT em.empNo,ISNULL(tf.cDate, '2012-10-09'),tf.cIn,tf.cOut
FROM filesTA tf Full Outer join Emp em On tf.runNo = em.empNo AND tf.cDate = '2012-10-09'
result from code Stored Procedure (On Datagridview display)
empNo| cDate | cIn | cOut
00001| 2012-10-09 00:00:00.000| 2012-10-09 07:21:00.000| 2012-10-09 20:34:00.000
00002| 2012-10-09 00:00:00.000| NULL | NULL
00003| 2012-10-09 00:00:00.000| NULL | NULL
00004| 2012-10-09 00:00:00.000| NULL | NULL
00005| 2012-10-09 00:00:00.000| 2012-10-09 07:36:00.000| 2012-10-09 17:04:00.000
00006| 2012-10-09 00:00:00.000| 2012-10-09 07:55:00.000| 2012-10-09 20:34:00.000
00007| 2012-10-09 00:00:00.000| 2012-10-09 07:50:00.000| 2012-10-09 00:00:00.000
00008| 2012-10-09 00:00:00.000| 2012-10-09 07:56:00.000| 2012-10-09 20:35:00.000
00009| 2012-10-09 00:00:00.000| 2012-10-09 07:57:00.000| 2012-10-09 20:32:00.000
00010| 2012-10-09 00:00:00.000| 2012-10-09 07:58:00.000| 2012-10-09 19:03:00.000
result from code Stored Procedure. it's not insert to sql. But show display on datagridview.
next Step. i need insert record '00002','00003','00003' or cIn and cOut = null
but i try insert that insert all record and duplicate value.
this code new.
Insert INTO filesTA (runNo,cDate,cIn,cOut)
VALUES (SELECT em.empNo,ISNULL(tf.cDate, '2012-10-09'),tf.cIn,tf.cOut
FROM filesTA tf Full Outer join Emp em On tf.runNo = em.empNo AND tf.cDate = '2012-10-09')
i need result from code Stored Procedure (On Datagridview display)
Thanks you for your time. 🙂
November 1, 2012 at 8:52 am
From your description it is very unclear what you are trying to do. Can you post ddl (create table scripts), sample data (insert statements) and desired output based on your sample data? Take a look at the first link in my signature for best practices when posting questions. Once we have something to work with and understanding of what you want to do the solution should be fairly quick to put together.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
November 1, 2012 at 9:48 am
This
i need don't duplicate value and insert some record.
and this
but i try insert that insert all record and duplicate value.
are contradictory statements. Your explanation needs to be clearer. Do you mean you need to insert all this data, but not duplicates? Or do you mean you want to insert all records and duplicates?
As Sean mentioned, post DDL and results, and please write more to explain what you need. "Some" is not a specific term. If you need all records, say that. If you need all non-duplicate records, say that. Also specify what is duplicate and what is not
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply