Click here to Skip to main content
15,895,011 members
Home / Discussions / Database
   

Database

 
AnswerRe: Difference between SqlCommand and SqlCommandBuilder Pin
Kschuler19-Sep-06 10:57
Kschuler19-Sep-06 10:57 
GeneralRe: Difference between SqlCommand and SqlCommandBuilder Pin
Rob Graham19-Sep-06 12:59
Rob Graham19-Sep-06 12:59 
QuestionReporting Services Parameter Dependencies Pin
CandyMe19-Sep-06 1:18
CandyMe19-Sep-06 1:18 
QuestionSelect Column (as Parameter) from Table Pin
CandyMe19-Sep-06 0:52
CandyMe19-Sep-06 0:52 
AnswerRe: Select Column (as Parameter) from Table Pin
_AK_19-Sep-06 1:28
_AK_19-Sep-06 1:28 
AnswerRe: Select Column (as Parameter) from Table Pin
albCode19-Sep-06 5:13
albCode19-Sep-06 5:13 
GeneralRe: Select Column (as Parameter) from Table Pin
CandyMe19-Sep-06 16:23
CandyMe19-Sep-06 16:23 
AnswerRe: Select Column (as Parameter) from Table Pin
Michael Potter20-Sep-06 5:32
Michael Potter20-Sep-06 5:32 
I usually write out the SQL Statement using place holders. In this case ?COLUMN_NAME? fills in for the variable that will be passed in. I then replace the place holders with using REPLACE. ** Be sure you read up on SQL Injection Attacks if you allow free form entry from the users.

This may not be as optimal as building the string on the fly but, it is much less error prone and much more maintainable.

CREATE PROCEDURE DynamicSqlTest
(
    @columnName NVARCHAR(100)
)
AS
 
DECLARE @sql NVARCHAR(1000)
 
SET  @sql = 
N'SELECT COLUMN_NAME AS Columns 
  FROM information_schema.columns 
  WHERE (TABLE_NAME = ''MyTable'') and 
  (COLUMN_NAME = ''?COLUMN_NAME?'')'
 
SET @sql = REPLACE(@sql,'?COLUMN_NAME?',@columnName)
 
EXEC(@sql)

GeneralRe: Select Column (as Parameter) from Table Pin
CandyMe20-Sep-06 17:20
CandyMe20-Sep-06 17:20 
QuestionSystem.Data.DB.ConcurrencyException Pin
kishorepv18-Sep-06 23:10
kishorepv18-Sep-06 23:10 
AnswerRe: System.Data.DB.ConcurrencyException Pin
_AK_19-Sep-06 1:32
_AK_19-Sep-06 1:32 
GeneralRe: System.Data.DB.ConcurrencyException Pin
kishorepv19-Sep-06 19:33
kishorepv19-Sep-06 19:33 
GeneralRe: System.Data.DB.ConcurrencyException Pin
_AK_19-Sep-06 19:36
_AK_19-Sep-06 19:36 
GeneralRe: System.Data.DB.ConcurrencyException Pin
kishorepv19-Sep-06 21:16
kishorepv19-Sep-06 21:16 
GeneralRe: System.Data.DB.ConcurrencyException Pin
_AK_19-Sep-06 21:21
_AK_19-Sep-06 21:21 
GeneralRe: System.Data.DB.ConcurrencyException Pin
kishorepv19-Sep-06 21:30
kishorepv19-Sep-06 21:30 
GeneralRe: System.Data.DB.ConcurrencyException Pin
_AK_19-Sep-06 21:37
_AK_19-Sep-06 21:37 
GeneralRe: System.Data.DB.ConcurrencyException Pin
kishorepv19-Sep-06 23:04
kishorepv19-Sep-06 23:04 
QuestionSearch for word in SP Pin
VK-Cadec18-Sep-06 7:35
VK-Cadec18-Sep-06 7:35 
AnswerRe: Search for word in SP Pin
Scott Serl18-Sep-06 9:58
Scott Serl18-Sep-06 9:58 
QuestionWhy are my tables 'read only'? Pin
Zdenek Navratil17-Sep-06 23:57
Zdenek Navratil17-Sep-06 23:57 
AnswerRe: Why are my tables 'read only'? Pin
Colin Angus Mackay18-Sep-06 3:21
Colin Angus Mackay18-Sep-06 3:21 
GeneralRe: Why are my tables 'read only'? Pin
Zdenek Navratil18-Sep-06 4:43
Zdenek Navratil18-Sep-06 4:43 
GeneralRe: Why are my tables 'read only'? Pin
Colin Angus Mackay18-Sep-06 5:41
Colin Angus Mackay18-Sep-06 5:41 
QuestionBook on Data Modeling Pin
Geethalakshmi17-Sep-06 20:20
Geethalakshmi17-Sep-06 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.