x
login about faq Site discussion (meta-askssc)

Query generation

I have created A table in sql server having following field
Name,
Created time,
Created date,

I want to display all the record of this table where created date will be system date and created time will before the current system time but on the current sytem date

Plz help me In generating this query

more ▼

asked Nov 13 '10 at 11:00 AM in Default

liferockzzzz gravatar image

liferockzzzz
11 1 1

The answer could depend on the data types you have chosen, please state what data types you are using for your fields.

Nov 13 '10 at 11:40 AM Kev Riley ♦♦

the datatype of created date and created time is nvarchar

Nov 13 '10 at 04:02 PM liferockzzzz

in that case what is the format of these strings that hold date and time?

Nov 14 '10 at 12:27 AM Kev Riley ♦♦
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first
Select Name, [created time], [created date] 
from ATable 
where [created date] = [system date] 
and [created time] < [system time]

might be what you want but as Kev says, it may well revolve around your data types.

I would also add its not a good practice to use column names with spaces, if you want to make them more readable then use an underscore, such as "created_date".

more ▼

answered Nov 13 '10 at 03:14 PM

Fatherjack gravatar image

Fatherjack ♦♦
38.8k 55 69 104

Oh no! You did it!! You have started the naming-conventions-discussion!!!

The advice should of course be: "If you want to make them more readable, then use PascalCase"

Sorry. Couldn't resist. Please ignore this comment... :)

Nov 13 '10 at 03:22 PM Magnus Ahlkvist

Impossible to ignore - I love it!

A blatant "case" of camelCase envy :)

Nov 13 '10 at 07:16 PM KenJ

...and name any foreign key columns exactly the same as the primary key columns they reference so BI tools like QlikView and PowerPivot can infer the relationships automatically. Nothing funny here, just saying...

Nov 13 '10 at 09:12 PM Scot Hauder
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x321

asked: Nov 13 '10 at 11:00 AM

Seen: 327 times

Last Updated: Nov 13 '10 at 03:11 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.