Click here to Skip to main content
15,910,123 members
Home / Discussions / Database
   

Database

 
GeneralRe: asp ado problem. Pin
Colin Angus Mackay29-Dec-04 1:33
Colin Angus Mackay29-Dec-04 1:33 
GeneralRe: asp ado problem. Pin
mysorian29-Dec-04 10:57
professionalmysorian29-Dec-04 10:57 
GeneralRe: asp ado problem. Pin
mysorian29-Dec-04 10:57
professionalmysorian29-Dec-04 10:57 
GeneralRe: asp ado problem. Pin
RomanD29-Dec-04 12:37
RomanD29-Dec-04 12:37 
GeneralRe: asp ado problem. Pin
Mike Dimmick30-Dec-04 3:58
Mike Dimmick30-Dec-04 3:58 
Generalsql exec Pin
SudeepPradhan28-Dec-04 13:59
SudeepPradhan28-Dec-04 13:59 
GeneralRe: sql exec Pin
Javier Lozano28-Dec-04 14:40
Javier Lozano28-Dec-04 14:40 
GeneralRe: sql exec Pin
Colin Angus Mackay28-Dec-04 14:44
Colin Angus Mackay28-Dec-04 14:44 
It isn't something SQL is very good at and the answer, at least as best as I can find it, is not pretty.

DECLARE @result int
DECLARE @sql nvarchar(500)
SET @sql = 'IF EXISTS(SELECT * FROM '+@Table+
           ') SELECT 1 AS Result ELSE SELECT 0 AS Result';
CREATE TABLE #Result (Result int)
INSERT INTO #Result
EXEC(@sql)
SELECT @result = Result FROM #Result
IF @result = 1
BEGIN
    -- This code is run if there are existing records in @table
END

DISCLAIMER: I typed this directly into Code Project, there may be errors

[EDIT]
Actually, after seeing Javier's solution I think that his is better on security grounds as it also helps protect against secondary sql injection attacks. Although, I would say that if your table contains a lot of rows then it would be slower as Javier's solution is returning all the rows in the table out of the Stored Procedure it is contained within in order to work out the number of rows.
[/EDIT]


Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums


GeneralAdding user-defined property to Access db Pin
sharonz28-Dec-04 6:06
sharonz28-Dec-04 6:06 
GeneralADO.net in unmanaged code Pin
MARROT28-Dec-04 4:42
MARROT28-Dec-04 4:42 
GeneralSame SQL Statement in access and in vb.net return difference result Pin
Mekong River27-Dec-04 21:30
Mekong River27-Dec-04 21:30 
GeneralRe: Same SQL Statement in access and in vb.net return difference result Pin
WoutL28-Dec-04 0:38
WoutL28-Dec-04 0:38 
GeneralRe: Same SQL Statement in access and in vb.net return difference result Pin
Mekong River28-Dec-04 10:16
Mekong River28-Dec-04 10:16 
GeneralRe: Same SQL Statement in access and in vb.net return difference result Pin
Mekong River28-Dec-04 14:56
Mekong River28-Dec-04 14:56 
GeneralQuerying CSV file using ODBC Pin
Wayne Phipps27-Dec-04 9:12
Wayne Phipps27-Dec-04 9:12 
GeneralMS-Access insert problem Pin
Imtiaz Murtaza27-Dec-04 0:38
Imtiaz Murtaza27-Dec-04 0:38 
GeneralRe: MS-Access insert problem Pin
Rob Graham31-Dec-04 3:54
Rob Graham31-Dec-04 3:54 
Questionhow to use ADO Event with VC6.0? Pin
深蓝26-Dec-04 19:26
深蓝26-Dec-04 19:26 
GeneralCrystal Reports... Pin
dSolariuM26-Dec-04 15:41
dSolariuM26-Dec-04 15:41 
GeneralSql variable Value Problem Pin
Hemant_Mane200325-Dec-04 3:14
sussHemant_Mane200325-Dec-04 3:14 
GeneralLooping Through Table Display Category Hierarchy Pin
tech@untouchable24-Dec-04 9:35
tech@untouchable24-Dec-04 9:35 
GeneralRe: Looping Through Table Display Category Hierarchy Pin
sreejith ss nair27-Dec-04 19:05
sreejith ss nair27-Dec-04 19:05 
GeneralRe: Looping Through Table Display Category Hierarchy Pin
Anonymous28-Dec-04 5:13
Anonymous28-Dec-04 5:13 
GeneralRe: Looping Through Table Display Category Hierarchy Pin
sreejith ss nair28-Dec-04 16:07
sreejith ss nair28-Dec-04 16:07 
QuestionSqlConnection string? Pin
murali_utr24-Dec-04 2:14
murali_utr24-Dec-04 2:14 

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.