Try this. I've pasted your code below exactly as it appears in a copy of cp page content to my clipboard:
Declare @dbname varchar(50),@sqlCommand varchar(1000)
Set @dbname ='dbname'
set @sqlCommand = '
SELECT RegDate, SID, Name, CAddress, TelEM1, TelEM2, Relation, Disablity, Loan, TRStatus
FROM' + @dbname + 'dbo.MemberRecord '
EXEC (@sqlCommand)
Ok. So insert this statement now, (right after the SET and before the EXEC):
PRINT @sqlCommand
And, comment out this statement:
EXEC(@sqlCommand)
Run the whole statement altered as above ...
SELECT RegDate, SID, Name, CAddress, TelEM1, TelEM2, Relation, Disablity, Loan, TRStatus
FROMdbnamedbo.MemberRecord
See what happened? There's no space between the word FROM and the @dbname variable's assigned value of 'dbname' nor is there a "dot" (.) designating the division between the schema name and the database. Usg the PRINT statement interspersed in your code is one method of debugging which is quite useful because it can be commented out easily to do successive tests.
That "." you're missing has to become part of your concatenation:
FROM ' + @dbname + '.' + 'dbo.MemberRecord'