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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] Using where clause

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2011-08-26 : 13:49:06
Wonder how I will be able to select on date and time when date and time are stored in 2 seperate fields.

I need to extract changed records from a table using DateChanged field and Timechanged field. I will be passing a datetime parameter as "changed since".

Can I somehow use the where clause for this?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-26 : 14:18:34
You could immediately separate the parameter and then use that in your where clause.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2011-08-26 : 15:36:31
Yes I can separate date and time from my parameter, but when I check on records that are to be included I need check both date an time as a group. I cannot check date by itself and time by itself. Since time belongs to date I need to combine somehow or?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-27 : 06:29:40
use same logic applied here

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=164765

and then where would be like

WHERE ModifiedDatefieldWithTime > = @parametervalue

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2011-08-29 : 13:13:57
I am able to test on separate date and time fields using this:

where      concat(shupmj,shtday) >= ''''' + @JdeTimeStamp + ''''' 


Thank you guys.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-29 : 13:18:48
whats concat? is it udf?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-29 : 13:23:03
snufse, that isn't going to scale well. Hopefully your table is tiny and won't care about the scan.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2011-08-29 : 14:46:51
"Concat" is concatenation and this is an AS400 (iSeries) syntax for db2/400

With the Concatenation Operator The concatenation operator (CONCAT or ||) combines two strings. The result of the expression is a string.


Is there a better alternative than using "concat"?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-29 : 15:10:12
Well you are posting your question on a Microsoft SQL Server site. You'll want to post your questions on a site that specializes in your dbms. The answer is going to be different for DB2.

But my point still remains about this concat thing going to cause performance issues.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2011-08-29 : 17:00:04
I am running my query from sql server 2005 box using linked server, rest of the code in the stored procedure is not related to db2/400.

SQL for db2/400 can handle 90% of std sql clauses except for a few.
Go to Top of Page
   

- Advertisement -