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
 General SQL Server Forums
 New to SQL Server Programming
 column alias asthe current time stamp

Author  Topic 

homer_dog
Starting Member

4 Posts

Posted - 2007-10-18 : 06:32:52
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

22859 Posts

Posted - 2007-10-18 : 06:35:12
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 - 2007-10-18 : 06:38:23
Thanks for your help i will try this code shortly
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-18 : 06:38:29
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

22859 Posts

Posted - 2007-10-18 : 06:40:17
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 - 2007-10-18 : 06:48:18
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

30421 Posts

Posted - 2007-10-18 : 06:51:23
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"
Go to Top of Page

homer_dog
Starting Member

4 Posts

Posted - 2007-10-18 : 06:54:39
Thank you both for your help
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-18 : 07:00:19
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

1 Post

Posted - 2012-12-26 : 01:13:33
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 - 2012-12-27 : 02:15:53
unspammed
Go to Top of Page
   

- Advertisement -