|
-
Sep 3rd, 2018, 12:45 PM
#1
Thread Starter
Don't Panic!
[RESOLVED] MS SQL - Dynamic SQL
Hi,
Situation:
A table of alterations which holds the old and new values (as Varchar).
A request from the client to not show the ID and show instead the interpreted data (ie name of a customer instead of their id).
I thought of just joining the table to the other table via id but had to utilise a convert function on the join to be able to run when a value in the log isnt a number.
I thought of using dynamic sql inside a stored proc to get a table of table names and fields and which field(s) to return. Pull back the log data into a temporary variable/table. Then loop the results, mount the Sql and get the actual data to show then update the temporary table before returning to the app to show in a grid.
I managed to get it to mount an SQL that looks correct, but MS Sql is complaining it cannot find the temporary table variable I defined.
The Questions are:
Is this possible?
When using the EXECUTE sp_executesql @newsql, does this create a separate instance type thing where it cannot see the variable declared already? Or so I need to pass the execution a pointer to the variable, somehow?
Any other ways I could try?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|