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.
| Author |
Topic |
|
toxicrainpx
Starting Member
8 Posts |
Posted - 2008-02-12 : 15:20:50
|
| Hello I'm not a SQL Expert but i'm using it for a few months. Now i need to use a variable that everytime that is called to a select into it gives the timestamp (or Stamp) to put on a specific field. The problem is that i need this variable not in bd conotation (like 2007-02-12 12:00:44:33) but like this 2007021212004433. Can someone help me? Thanks in advance. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-02-12 : 15:31:09
|
| Do not change the format of the stored data. When you extract the data to be displayed by your application, format it at that time via your front-end application.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-02-12 : 15:34:08
|
quote: Now i need to use a variable that everytime that is called to a select into it gives the timestamp
Take a look at the function: GETDATE() in Books Online.Be One with the OptimizerTG |
 |
|
|
toxicrainpx
Starting Member
8 Posts |
Posted - 2008-02-12 : 17:36:22
|
| I dont need to change the format. I use an aplication that uses a field called stamp. That field contains unique number inside.I need to generate a random number to use when I'm using query based functions on SQL and not on the aplication. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-02-12 : 17:40:11
|
Random number?SELECT ABS(CHECKSUM(NEWID())) % 100000will give you random number between 0 and 99999 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
pravin14u
Posting Yak Master
246 Posts |
Posted - 2008-02-13 : 01:03:36
|
| declare @s1 varchar(17)select @s1=convert(varchar,datepart(yy,getdate()))+ convert(varchar,datepart(m,getdate()))+convert(varchar,datepart(dd,getdate()))+convert(varchar,datepart(hh,getdate()))+convert(varchar,datepart(n,getdate()))+convert(varchar,datepart(s,getdate()))+convert(varchar,datepart(ms,getdate()))But as Peso has pointed out, generating a random number with current time as Seed would be the optimal solution |
 |
|
|
|
|
|
|
|