SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 column alias asthe current time stamp
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

homer_dog
Starting Member

4 Posts

Posted - 10/18/2007 :  06:32:52  Show Profile  Reply with Quote
Hey All,
I am new to programming in SQL developer and I was hoping one of you kind salmon of knowledge could help me
I am running an SQL script every 15 minutes to pull data. I would like to insert the results into a column in a table. I have two issues:
1.How can I give the result column the current time stamp as an alias?
2.How can I add this column to the results table (I know its Alter table but do I put this into the insert sql?)

I would appreciate any help possible
Thanks

Kristen
Test

United Kingdom
22431 Posts

Posted - 10/18/2007 :  06:35:12  Show Profile  Reply with Quote
1 SELECT GetDate() AS [Now]

2:

INSERT INTO MyTable(NowColumn, Col1, Col2, ...)
SELECT GetDate(), Col1, Col2, ...
FROM MyOtherTable

Kristen
Go to Top of Page

homer_dog
Starting Member

4 Posts

Posted - 10/18/2007 :  06:38:23  Show Profile  Reply with Quote
Thanks for your help i will try this code shortly
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30282 Posts

Posted - 10/18/2007 :  06:38:29  Show Profile  Visit SwePeso's Homepage  Reply with Quote
I guess you are right Kristen but it sounds like he wants

SELECT Value AS [2007-10-18]
FROM Table1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Kristen
Test

United Kingdom
22431 Posts

Posted - 10/18/2007 :  06:40:17  Show Profile  Reply with Quote
Well I've reread it and it reads your way for point 1, and my way for point 2.

Time will tell, I expect!
Go to Top of Page

homer_dog
Starting Member

4 Posts

Posted - 10/18/2007 :  06:48:18  Show Profile  Reply with Quote
Sorry I’m confused
Here is my code

SELECT Operation, sum(QTY)as[This is where I would like the time stamp]
FROM tblActualWIP
Where datediff(day,[Date Entered Op],getdate())<4
group by Operation

Do I need to declare my column alias as a variable at the top ie
declare @Now datetime
select @Now = (select getdate())
select sum(QTY) as @date

I think I'm nearly there
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30282 Posts

Posted - 10/18/2007 :  06:51:23  Show Profile  Visit SwePeso's Homepage  Reply with Quote
I guess you later want to add a column very 15 minutes to your target table?
And then upsert the new column?

Bad design. Don't quit your day job.

It is better as Kristen suggests. Have a column for Now and then you can present the data
CROSSTAB/PIVOT style later if you want to.

Don't mix up presentation layout with table design.

See http://www.datamodel.org/NormalizationRules.html



E 12°55'05.25"
N 56°04'39.16"

Edited by - SwePeso on 10/18/2007 06:52:14
Go to Top of Page

homer_dog
Starting Member

4 Posts

Posted - 10/18/2007 :  06:54:39  Show Profile  Reply with Quote
Thank you both for your help
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22775 Posts

Posted - 10/18/2007 :  07:00:19  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by homer_dog

Sorry I’m confused
Here is my code

SELECT Operation, sum(QTY)as[This is where I would like the time stamp]
FROM tblActualWIP
Where datediff(day,[Date Entered Op],getdate())<4
group by Operation

Do I need to declare my column alias as a variable at the top ie
declare @Now datetime
select @Now = (select getdate())
select sum(QTY) as @date

I think I'm nearly there



Where do you want to show data?
If you want to show in the front end, can you just get date and then display it?

or

think if you need the code like this really?

declare @Now datetime, @sql varchar(8000)
select @Now = (select getdate())
set @sql='select sum(1) as ['+cast(@now as varchar(30))+']'
exec(@sql)



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Evangelinevtw
Starting Member

Libya
1 Posts

Posted - 12/26/2012 :  01:13:33  Show Profile  Reply with Quote
robert g allen books avatar game boy shaved ice machines cross pen roboticarm robotica pharmacy technician certification practice exam pet mice buy convertible battery chargers aa [url=http://www.coachbagjpn.com/]?????[/url]
sony icf c212 lib hcn4226w secretos de belleza snoot scuba regulators pccard baby's crib divorce your parents natural cures for depression [url=http://www.pradaoutlettokyo.com/]??? ??[/url]
organix pet food welding secrets intranet service learning acer monitor 19 [url=http://www.coachbagrakuten.com/]????????[/url]
primo eurobath motorola h700 headset bath beads sharp cash registers pentax af 500 ftz
Go to Top of Page

gtopawb
Starting Member

5 Posts

Posted - 12/27/2012 :  02:15:53  Show Profile  Reply with Quote
unspammed
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000