473,468 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Executing sql statements

When i execute the following in Sql query anlyzer

Declare @dbname varchar(30),
@str varchar(500),
@emailID varchar(50)
set @Em**************@yahoo.com'

set @dbname='DB_kms_prv'

set @str='SELECT empid, NTName, officialEmail, PreferredName FROM ' +
@dbname + '.dbo.tblEmployee where officialEmail=' + @emailID
exec (@str)
I get error message

The column prefix 'santosh@yahoo' does not match with a table name or
alias name used in the query.
How to get rid of it..?
Jul 23 '05 #1
1 1107
You need to put single quotes around the address:

set @str='SELECT empid, NTName, officialEmail, PreferredName FROM ' +
@dbname + '.dbo.tblEmployee where officialEmail=''' + @emailID + ''''

If you get syntax errors from dynamic SQL, then just 'SELECT @sql'
before executing it, so you can see what the statement looks like -
that makes the problem much clearer.

But don't use dynamic SQL at all unless it's absolutely necessary - see
here for all the reasons why to avoid it, and alternative solutions:

http://www.sommarskog.se/dynamic_sql.html

Specifically for your case, see "Getting data from another database" in
this section:

http://www.sommarskog.se/dynamic_sql.html#Dyn_Db

Simon

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Faden | last post by:
Hi, Given arbitrary Python source code input by the user, I want to get the result of executing that source as an expression if it is an expression and otherwise execute the source as a...
8
by: MrTrix | last post by:
Hello: I'm having a problem formulating the code to execute a multiple line command. I'm trying to execute something like: set rowcount 100000 declare @rowct int select @rowct = 1 while...
3
by: Dean g | last post by:
Hi, I have a problem with running multiple sql statements using asp. Basically if there is an error with any of the statements inside the query a rollback is done. the sql and rollback work fine,...
10
by: Heiko Pliefke | last post by:
Hi NG! I wrote a stored procedure which at first deletes 100.000 rows and then inserts 100.000 new rows. There is a huge difference between executing this SP in the query-analyzer (runtime...
1
by: rudykayna | last post by:
I'm having trouble executing multiple DDL statements in one SQL file. I've been using ExecuteNonQuery() but it does not seem to like the "GO" statements in my SQL file. I need to keep the "GO"...
8
by: lovecreatesbea... | last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, ... . "Non-automatic variables are...
0
by: wugon.net | last post by:
Hi , Anyone know how to monitor db2 trigger activity ? We suffer some trigger issue today and we try to monitor trigger's behavior use event monitor and db2audit, but both tools can not get...
2
by: krishna.000.k | last post by:
file1.py ---------- a = 20 from abc import * print "Should this be printed when 'a' is alone imported from this module" file2.py ---------- from file1 import a
1
by: bill | last post by:
Here's a question about getting the most out of the interface when executing SQL in the interactive window of M In TOAD (a popular front end for Oracle by Quest Software), the equivalent of the...
3
by: PatrickF | last post by:
Hi, I am writing a simulator for a game. I have been stuck at a couple if statements executing regardless of false conditions every time the flow of execution reaches it. Here's the format with...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.