Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 inserting both Values in single statement

Author  Topic 

mounikakala
Starting Member

14 Posts

Posted - 2008-08-26 : 13:05:30
Hi,

I have the following situation.

Each Day I run a report for the Distinct list of records which meet my filtering criteria, and then update a table with those

records along with that distinct records

the Following example would explain

My table Structure would be with 2 columns as Name Varchar(30) and Date Datetime

I am writing a report for the people who met a certain criteria and found 10 records for the day.


Now I can insert the Name Values into the table with my structure but I have problem inserting the toDay's Value into the Table in

a single statement.

how do I insert the Values in a single statement


Thanks

Mounika

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-26 : 13:13:41
INSERT INTO ...
SELECT ...

If that doesn't help you, then please show us a data example of what you mean.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-26 : 13:22:34
quote:
Originally posted by mounikakala

Hi,

I have the following situation.

Each Day I run a report for the Distinct list of records which meet my filtering criteria, and then update a table with those

records along with that distinct records

the Following example would explain

My table Structure would be with 2 columns as Name Varchar(30) and Date Datetime

I am writing a report for the people who met a certain criteria and found 10 records for the day.


Now I can insert the Name Values into the table with my structure but I have problem inserting the toDay's Value into the Table in

a single statement.

how do I insert the Values in a single statement


Thanks

Mounika


did you meant current days date? then uise getdate()

INSERT INTO YourTable
SELECT Name,GETDATE()
FROM table
Go to Top of Page

mounikakala
Starting Member

14 Posts

Posted - 2008-08-26 : 15:13:56
Hi Look at the Example.

My Transaction Table has Millions of records. Out of which there can be 200,000 Records per day.
So I cannot give the Sample data based on that. Now my requirement is that on any Given Day, I can query for the
distinct Names that macth my search criteria. But the Query results a list of Names.


Table Structure is like This.


Name Date
----------------------





I am able to Query the records and Insert into the table in a single shot and the table looks like this. And then I am updating the Table with the getdate()
Value where ever the Date is Null.


Name Date
----------------------
A
B
C
D
E
F
G
H


but I need to Insert into the table both the Name and Date Value at the same time and the date value will be Same All the records with the Date value on
which day I run the query.

Name Date
----------------------
A Aug 26 2008
B Aug 26 2008
C Aug 26 2008
D Aug 26 2008
E Aug 26 2008
F Aug 26 2008
G Aug 26 2008
H Aug 26 2008



I hope this is clear.

Thanks

Mounika
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-26 : 23:51:28
What you can given here can be achieved by using query that i've given. did you try it?
Go to Top of Page
   

- Advertisement -