x

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, 2010 at 11:00 AM in Default

liferockzzzz gravatar image

liferockzzzz
11 2 2

The answer could depend on the data types you have chosen, please state what data types you are using for your fields.
Nov 13, 2010 at 11:40 AM Kev Riley ♦♦
the datatype of created date and created time is nvarchar
Nov 13, 2010 at 04:02 PM liferockzzzz
in that case what is the format of these strings that hold date and time?
Nov 14, 2010 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, 2010 at 03:14 PM

Fatherjack gravatar image

Fatherjack ♦♦
42.6k 75 79 108

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, 2010 at 03:22 PM Magnus Ahlkvist

Impossible to ignore - I love it!

A blatant "case" of camelCase envy :)
Nov 13, 2010 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, 2010 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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x371

asked: Nov 13, 2010 at 11:00 AM

Seen: 461 times

Last Updated: Nov 13, 2010 at 03:11 PM