Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6355003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:40:46+00:00 2026-05-24T22:40:46+00:00

I am performing the below operation. I am getting the error and unable to

  • 0

I am performing the below operation. I am getting the error and unable to find what the error is.Could any one help me finding it.
a) Check for the availability of DESTINATION data base. If it is not exist, create the data base and move the tables to the data base.
b) If the table exists in the DESTINATION data base then no process required for the table.

if db_id('Destination')is null
begin
Create database Destination
select * into TabDestination from [Source].[dbo].[TabSource]
end 
else
begin
use Destination
go
if('TabDestination' in (select name from sys.objects where type = 'u'))
insert into TabDestination select * from [Source].[dbo].[TabSource]
end

I am getting fallowing error

Msg 911, Level 16, State 1, Line 8
Database 'Destination' does not exist. Make sure that the name is entered correctly.
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'end'.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:40:46+00:00Added an answer on May 24, 2026 at 10:40 pm

    Few problems here:

    • After Create database Destination you need to use that database before you do the select * into TabDestination... as you will create TabDestination in some other DB.
    • The Go in the middle of the begin...end block won’t work.
    • To specify your database for the inserts to TabDesitination you’d be better to use the fully qualified name of the table than calling Use, eg Insert Destiation.dbo.TabDestination...
    • You need to use If Exists (select... for the second if statement.
    • Because your Database may not exists when the script compiles, a lot of the sql needs to be exec’d dynamically.

    So your script could be re-written as:

    if db_id('Destination')is null
    begin
        Create database Destination    
        exec ('select * into Destination.dbo.TabDestination from [Source].[dbo].[TabSource]')
    end 
    else
    begin
    
        if exists (select name from Destination.sys.objects where name = 'TabDestination' and type = 'u')
        insert into Destination.dbo.TabDestination select * from [Source].[dbo].[TabSource]
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While performing a conditional DELETE operation in one of my InnoDB tables, which apparently
When performing many disk operations, does multithreading help, hinder, or make no difference? For
I'm performing a nested loop in python that is included below. This serves as
Can someone advise me if I am performing the below steps correctly: When a
I am performing a least squares regression as below (univariate). I would like to
Is the snippet below safe for performing some initialization once in a multithreaded program?
While performing a refactoring, I ended up creating a method like the example below.
Okay I have the below code performing something I don't want it to do.
I am performing a query which returns a list of comments as shown below:
I have the below method where I need to check for some certain strings

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.