Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
Use Table Column Contents As Where Clause
Use Table Column Contents As Where Clause
Rate Topic
Display Mode
Topic Options
Author
Message
Derek-918769
Derek-918769
Posted Saturday, December 06, 2008 1:07 AM
Forum Newbie
Group: General Forum Members
Last Login: Thursday, April 15, 2010 1:42 PM
Points: 4,
Visits: 8
Hello, I'm hoping someone has come across a similar issue and may have a solution for me.
Currently have the following table setup (only showing affected columns). Column list is as follows:
Table Name: tblActivity (tblDenyActivity)
DenyDateUserID
DenyDate
InvalidDate
Table Name: tblUserData
UserID
Table Name: tblUserSkillset
UserID
SkillsetTypeID
Table Name: tblSkillsetType
SkillsetTypeID
SkillSetType
SQLSnippet
SELECT tblDenyActivity.DenyDateUserID, tblDenyActivity.DenyDate FROM dbo.tblActivity AS tblDenyActivity INNER JOIN
dbo.tblUserData ON tblDenyActivity.DenyDateUserID = dbo.tblUserData.UserID AND tblDenyActivity.InvalidDate IS NULL INNER JOIN dbo.tblUserSkillset ON dbo.tblUserData.UserID = dbo.tblUserSkillset.UserID INNER JOIN dbo.tblSkillsetType ON dbo.tblUserSkillset.SkillsetTypeID = dbo.tblSkillsetType.SkillsetTypeID
WHERE (dbo.tblSkillsetType.SQLSnippet)
The column SQLSnippet will contain something like the following (DenyDate IS NOT NULL AND DATEDIFF(dd,DenyDate,GETDATE()) > 31)
So my end result would be:
SELECT tblDenyActivity.DenyDateUserID, tblDenyActivity.DenyDate FROM dbo.tblActivity AS tblDenyActivity INNER JOIN
dbo.tblUserData ON tblDenyActivity.DenyDateUserID = dbo.tblUserData.UserID AND tblDenyActivity.InvalidDate IS NULL INNER JOIN dbo.tblUserSkillset ON dbo.tblUserData.UserID = dbo.tblUserSkillset.UserID INNER JOIN dbo.tblSkillsetType ON dbo.tblUserSkillset.SkillsetTypeID = dbo.tblSkillsetType.SkillsetTypeID
WHERE (DenyDate IS NOT NULL AND DATEDIFF(dd,DenyDate,GETDATE()) > 31)
Has anyone ever tried to do anything like this?
Post #615077
GilaMonster
GilaMonster
Posted Saturday, December 06, 2008 1:32 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 11:21 AM
Points: 37,686,
Visits: 29,943
The only way to do that is to use dynamic SQL, build up the final query and then use sp_executeSQL to run it.
Be aware of the downsides of dynamic SQL and watch for SQL injection.
Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild
: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter
We stand on the bridge and no one may pass
Post #615084
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.